Question

We are using a Ubuntu+nginx+php5-fpm combination on our servers with PHP version being 5.5. We are trying to run index.php which includes a bunch of phar files. Something like:

<?php
include "a.phar";
include "b.phar";
//...
?>

When this script is run from the command line PHP, it works fine. When this is run from either php Development server (php -S) or from nginx, we get the following error:

2013/11/18 17:56:06 [error] 14384#0: *597 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Cannot redeclare class Extract_Phar in b.phar on line 103

I don't have a class called Extract_Phar - so I presume that my build process is adding it somewhere along the way. I have used phing to build the same, just in case that helps. The phing target is:

<target name="phar" depends="prepare">
  <pharpackage destfile="./build/phar/LogUtils.phar" 
  basedir="./build/intophar"
  compression="bzip2">
  <fileset dir="./build/intophar/">
    <include name="*.*" />
    <include name="**/**" />
  </fileset>
  <metadata>
    <element name="version" value="1.0" />
    <element name="authors">
       <element name="Shreeni">
         <element name="e-mail" value="test@test.com" />
       </element>
    </element>
  </metadata>
  </pharpackage>
</target>

And the index.php in my intophar folder is something like:

include("api/LogUtils.inc.php");
// Other relative include statements

I have played around with apc flags based on other answers and have set the following:

apc.include_once_override = 0 
apc.canonicalize = 0 
apc.stat = 0
apc.enabled=0 
apc.enabled_cli=0
apc.cache_by_default = 0

None of this helps and we are unable to run our code. ANy suggestions?

Was it helpful?

Solution

The problem might be happening because of conflicting stubs in your various phar files. Try:

<?php
include "phar://a.phar/index.php"; // Assuming that the stub is index.php
include "phar://b.phar/index.php"; // Assuming that the stub is index.php
//...
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top