1

I've a problem with a simple chdir and require.

From a first file : web/index_cluster.php

I'm trying to load a second one : ezpublish_legacy/index_cluster.php

My required file do not load but I've no clue why...


Here's my config.

  • PHP 5.4.16
  • Upgrading from eZ Publish 4.7 to eZ Pubslih 5.90.0alpa1 (based on SF2)
  • Red Hat Enterprise Linux Server release 6.4 (Santiago)

There is nothing on ezpublish log and a Allowed memory size in apache

PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 240 bytes) in /path/to/my/www/web/index_cluster.php on line 11

Here's my (simplified) tree

www
    `-- ezpublish_legacy
        |-- index_cluster.php
    `-- web
        |-- index_cluster.php

Here's the original code

$legacyRoot = '/path/to/my/www/ezpublish_legacy';
chdir( $legacyRoot );
require 'index_cluster.php';

And here's my fix

$legacyRoot = '/path/to/my/www/ezpublish_legacy';
chdir( $legacyRoot );
require '/path/to/my/www/ezpublish_legacy/index_cluster.php';


I've tried everything I could think of :

$legacyRoot = '/path/to/my/www/ezpublish_legacy';
require $legacyRoot.'/index_cluster.php';

=> Working


$legacyRoot = '/path/to/my/www/ezpublish_legacy';
echo getcwd() . "\n";
chdir( $legacyRoot );
echo getcwd() . "\n";
die()
require 'index_cluster.php';

=> exactly what I'm expecting

/path/to/my/www/web
/path/to/my/www/ezpublish_legacy

Loading with absolute path and checking current directory on loaded file is giving the expected result

web/index_cluster.php

require '/path/to/my/www/ezpublish_legacy/index_cluster.php';

ezpublish_legacy/index_cluster.php

echo getcwd() . "\n";
die();

result in (what I'm expecting)

/path/to/my/www/web

web/index_cluster.php

$legacyRoot = '/path/to/my/www/ezpublish_legacy';
chdir( $legacyRoot );
require '/path/to/my/www/ezpublish_legacy/index_cluster.php';

ezpublish_legacy/index_cluster.php

echo getcwd() . "\n";
die();

result in (what I'm expecting)

/path/to/my/www/ezpublish_legacy

Update : I've tried something new :

require "/index_cluster.php" => instant fail

PHP Warning: require(/index_cluster.php): failed to open stream: No such file or directory in /path/to/my/www/web/index_cluster.php on line 11

require "index_cluster.php" => trying loading for 10 seconds then fail

PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 240 bytes) in /path/to/my/www/web/index_cluster.php on line 11


Gogol
  • 3,033
  • 4
  • 28
  • 57
Adcaelo
  • 19
  • 5
  • Your error message is about PHP memory limit. It is not about chdir & require. – Taras Jun 17 '16 at 10:18
  • true, I had forgotten this apache error when first writing because it's not "relevant" for me... Added it afterwards. Nonetheless problem still is caused by a chdir/require combo – Adcaelo Jun 17 '16 at 10:31
  • * not relevant because I've forced my php memory limit to 2G and more and same thing ! PHP Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 130968 bytes) – Adcaelo Jun 17 '16 at 10:33
  • Is there a specific reason why you're upgrading to an alpha release? Have you tried upgrading to the most recent stable release instead? – Simba Jun 17 '16 at 10:48
  • I've no idea why we're using an alpha relase, in fact it's a "corporate" fork based on the alpha – Adcaelo Jun 17 '16 at 11:06

2 Answers2

1

An include or require which is not starting with ./, / or, on Windows, a drive letter is different from the others by using include_path. To solve your immediate issue you can use

require "./index_cluster.php"

to use a fixed relative path. You tried the absolute path /index_cluster.php which would look on filesystem root, not the actual location.

When not using this form but a plain

require "index_cluster.php"

this will search through the include_path. The include_path on my system looks like this:

$ php -r 'echo ini_get("include_path");'
.:/usr/share/php:/usr/share/pear

So PHP would look for these files in order:

./index_cluster.php
/usr/share/php/index_cluster.php
/usr/share/pear/index_cluster.php

Using include_path is bad because some systems are configured wrongly and miss . and this takes more time. Also, and that's what's hitting you, for processing a little bit more memory is required, that's why you're hitting the memory limit in this case. To fix this for longer term you should analyze the code, if you can reduce memory usage and if not probably increase the memory_limit in php.ini.

johannes
  • 15,807
  • 3
  • 44
  • 57
  • Lost on my numerous test I've not thought for a seconde that /index_cluster.php would check on system_root not folder, I was looking for my $legacyRoot . "/index_cluster.php". – Adcaelo Jun 17 '16 at 11:00
  • require "./index_cluster.php" **works great**, 3 people looking at the same piece of code did not thought of this... thank you... but require "index_cluster.php" should work too, so it's an apache / php configuration about include_path that's too restrictive. **Am I right ?** – Adcaelo Jun 17 '16 at 11:03
  • No, not include_path is the issue. It is that your application requires lots of memory and is close to the limit. Anything could hit the limit. Either optimize the application or increase memory_limit, see http://php.net/memory_limit – johannes Jun 17 '16 at 11:09
  • In fact, my 2 file having the same name, it's looping on the first one instead of including the 2nd one... I've add an error_log('test'); on my file and i can see apache log adding hundreds of new lines [Fri Jun 17 13:40:34 2016] [error] [client 10.146.50.128] test – Adcaelo Jun 17 '16 at 11:42
  • changing my 2nd file to index_cluster_zzz.php it's working with the "require "index_cluster_zzz.php" – Adcaelo Jun 17 '16 at 11:42
  • Ah so your issue is probably that you're building an infinite recursion with includes somehow? Easy solution: Use `require_once`, better solution: Review your code and search for the issue of that (http://php.net/inclued can help, but is not trivial to get working) – johannes Jun 17 '16 at 12:27
0

PHP configuration about "include_path" create a "loop" and a memory limit because my 2 files have the same name.

So web/index_cluster.php load indefinitely itself instead of loading ezpublish_legacy/index_cluster.php

which config exactly is not releavant to me because it's a iso-production config I cannot change.

Available solution (pick one)

  • Use absolute path for require
  • Rename 1 of the 2 files with another name
  • Search and correct your php config about include_path
Adcaelo
  • 19
  • 5