[php-maint] Bug#614904: php5-cgi: fastcgi breaks __COMPILER_HALT_OFFSET__

Pascal COURTOIS Pascal.Courtois at nouvo.com
Thu Feb 24 16:35:44 UTC 2011


obviously it's a memory leak. The following program should always print the same offset (last print before __halt_compiler() )
after few calls result become different.

<?php
  header("Content-type: text/plain");
  print "posix_getpid ".posix_getpid()."\n";
  if (!defined('__COMPILER_HALT_OFFSET__'))
      {
        print "not defined\n";
        $COMPILER_HALT_OFFSET=00000000;
        if ($COMPILER_HALT_OFFSET==0)
          {
            $fh = fopen(__FILE__, 'r+');
            $ok=0;

            $offset_file=-1;
            while(!$ok && ($line = fgets($fh)))
              {
                if ($offset_file<0 && preg_match("/^.*COMPILER_HALT_OFFSET=(00000000)/",$line,$matches,PREG_OFFSET_CAPTURE))
                  {
                    $offset_file=$pos+$matches[1][1];
                  }
                if (preg_match("/^.*(__halt_compiler\(\);)/",$line,$matches,PREG_OFFSET_CAPTURE))
                  {
                    $COMPILER_HALT_OFFSET=$pos+$matches[1][1]+18;
                    $ok=1;
                  }

                $pos=ftell($fh);
              }

            if (!$ok)
              {
                die("PHP 5.3 with fastcgi bug could not be corrected");
              }

            $computed_offset=sprintf("%08d",$COMPILER_HALT_OFFSET);
            print "computed_offset:".$computed_offset."\n";
            fseek($fh,$offset_file);
            fwrite($fh,sprintf("%08d",$COMPILER_HALT_OFFSET));
            fclose($fh);

          }
      }
    else
      $COMPILER_HALT_OFFSET=__COMPILER_HALT_OFFSET__;

  print "offset:".$COMPILER_HALT_OFFSET."==\n";

  __halt_compiler();abcd





More information about the pkg-php-maint mailing list