Php5-FPM error while including multiple phar files
Asked Answered
B

1

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="[email protected]" />
       </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?

Broadcloth answered 18/11, 2013 at 10:6 Comment(6)
without seeing your build process, nobody can help you.Haggard
@Haggard Added more details of the build process. Let me know if you think more info is needed.Broadcloth
is phar enabled in your fpm version of php?Haggard
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 OnBroadcloth
The formatting on the previous comment is kind of broken, but it seems that it is enabled - bz2 is enabled too.Broadcloth
I have confirmed that the code works when I include one phar file. It is the second one that causes the error message.Broadcloth
A
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
//...
?>
Ailis answered 19/11, 2013 at 11:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.