Solution: Building php-cli for eZ publish command line scripts

This is compatible with PHP 4.4.x

About

Building standalone php-cli (php 4.4.4 + refcount patch) for eZ publish

The Patch

eZ publish and eZ publish command line scripts like the update scripts which interact with the content object database can use so many references that it causes PHP to segfault, crash, fail, die ...

This problem has been around for a long time and has only partially been resolved in PHP 4.4.x.

To help reduce the chance PHP might segfault, one may 'patch' PHP source code and recomple PHP.

Refcount (Increased Reference Support) Patch from http://ilia.ws/archives/5-Top-10-ways-to-crash-PHP.html

Index: zend.h
 ====================================
 RCS file: /repository/Zend/Attic/zend.h,v
 retrieving revision 1.164.2.21
 diff -u -3 -p -r1.164.2.21 zend.h
 --- zend.h      16 Mar 2004 17:36:17 -0000      1.164.2.21
 +++ zend.h      14 Apr 2004 18:01:37 -0000
 @@ -263,7 +263,7 @@ struct _zval_struct {
         zvalue_value value;             /* value */
         zend_uchar type;        /* active type */
         zend_uchar is_ref;
 -       zend_ushort refcount;
 +       int refcount;
  };

Patching PHP

Here are the commands I used today patch the php-cli source to include improved reference support.

# php-cli (php 4.4.4) compile instructions:
 
lynx http://www.php.net/get/php-4.4.4.tar.gz/from/a/mirror
 
tar -vzxf php-4.4.4.tar.gz
 
cd php-4.4.4
 
# apply patch
 
vi Zend/zend.h

Building PHP

Here are the commands I used today to compile php-cli from source.

mkdir /usr/local/php-cli-4-4-4-refcount
 
./configure --prefix=/usr/local/php-cli-4-4-4-refcount --disable-cgi
 
make
 
make test
 
make install-cli

Testing

Use this patched php-cli binary to run your eZ publish command line, cronjob, update scripts

Example Use Case

/usr/local/php-cli-4-4-4-refcount/bin/php -d memory_limit=456M -C update/common/scripts/updatesearchindex2.php -s admin-dev -dall  --logfiles --verbose | tee ez.script.index-2006-11-14-0006.log

Another Patch

Another patch has been documented to solve other reference related problems related to eZ publish's PHP code. If the above patch does not solve your breakdowns, consider applying this other patch and test the results.

References