0

I had this bug at work today - won't be able to test it until I get back there after the weekend but thought someone might know the answer offhand.

I have two scripts, file_1.php and file_2.php. They are located in the same folder within my codebase. Said codebase includes many many files, including a global 'header' file which calls several other files and pretty much sets up any file to run on our environment.

What I would like to do is run file_2.php from within a shell_exec() or exec() from file_1.php. However, when I do this, file_2.php doesn't recognize the file 'header.php' unless provided with the absolute filepath, and even when it is provided, not all calls to other files (there are several includes, requires, etc, in header.php) succeed - though some do.

At the point where I left it, the latest file that was not included had been correctly identified by providing the complete filepath to it as well (as opposed to only the relative one), but I received an 'unidentified function' error on apache_note(), which is a function bundled with PHP.

I'm running these from the command line, and when I run only test_2.php alone it works fine, but when it is accessed by way of exec() from file_2.php, this is my situation. Is there something I'm missing about exec()? Is there a way to run the second file as if in exactly the same environment as the first one? (I tried putenv() with no success, but perhaps there's a trick involving that?

Help or ideas greatly appreciated, though I won't be able to check for a couple of days. Happy Thanksgiving to all ;)

BIU
  • 2,340
  • 3
  • 17
  • 23
  • Have you tried `require()`'ing header.php using path preceded with `__DIR__`? – Tomasz Kowalczyk Nov 27 '14 at 22:26
  • I was using our SYSTEM_BASEDIR global variable, passed in from file_1.php, which I believe uses that. I'll double check though, thanks for the idea – BIU Nov 27 '14 at 22:28
  • `shell_exec()` and similar may run from the current user's home directory, that would be my wild guess. – Tomasz Kowalczyk Nov 27 '14 at 22:29
  • Going to try this as well http://stackoverflow.com/questions/9636605/export-shell-environment-variable-before-running-command-from-php-cli-script – BIU Nov 27 '14 at 22:59

0 Answers0