9

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?

Shreeni
  • 3,092
  • 7
  • 24
  • 39
  • without seeing your build process, nobody can help you. – cweiske Nov 18 '13 at 10:10
  • @cweiske Added more details of the build process. Let me know if you think more info is needed. – Shreeni Nov 18 '13 at 10:15
  • is phar enabled in your fpm version of php? – cweiske Nov 18 '13 at 11:24
  • From phpinfo: Phar Phar: PHP Archive support enabled Phar EXT version 2.0.1 Phar API version 1.1.1 Phar-based phar archives enabled Tar-based phar archives enabled ZIP-based phar archives enabled gzip compression enabled bzip2 compression enabled Directive Local Value Master Value phar.cache_list no value no value phar.readonly Off Off phar.require_hash On On – Shreeni Nov 18 '13 at 13:00
  • The formatting on the previous comment is kind of broken, but it seems that it is enabled - bz2 is enabled too. – Shreeni Nov 18 '13 at 13:02
  • I have confirmed that the code works when I include one phar file. It is the second one that causes the error message. – Shreeni Nov 18 '13 at 13:08

1 Answers1

5

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
//...
?>
Mohamed Yasin
  • 440
  • 3
  • 10