0

I have a PHP script which is failing on a require_once() statement, and I can't figure out why. Here is some test code I've come up with:

if(require_once("lib/modules/events/events.inc.php")){ print "Events module loaded!"; }
if(require_once("lib/modules/events/bills.inc.php")){ print "Bills module loaded!"; }

The first line works fine.

The second line fails. If I try commenting out the first line and running the second line by itself, I get a blank white page, and the headers that the server sends say "500 Internal Server Error."

Apache is not logging this error, as far as I can tell. There is only one error_log file (I checked all the vhosts, and they all use the default error_log). If I tail -f /var/log/httpd/error_log and reproduce the problem, nothing is logged.

I have verified that both files exist, in the same directory, and have the same permissions:

# ls -hal *.inc.php
-rwxrwxr-x. 1 wdmartin wdmartin 83K Aug 15 11:30 bills.inc.php
-rwxrwxr-x. 1 wdmartin wdmartin 15K Mar  5  2015 events.inc.php

Since the server is RHEL with SE Linux, I've checked that they both have the same SE Linux security context:

# ls -Z *.inc.php
-rwxrwxr-x. wdmartin wdmartin unconfined_u:object_r:httpd_sys_content_t:s0 bills.inc.php
-rwxrwxr-x. wdmartin wdmartin unconfined_u:object_r:httpd_sys_content_t:s0 events.inc.php

According to get_include_path, the include path starts with ., which should work because the paths were constructed to start relative to executing script. And it DOES work for the events.inc.php file. It's just the bills.inc.php file in the same folder that doesn't work.

I tried opening both files in a hex editor to see if one or the other of them had a UTF-8 byte order mark, since those can sometimes trip up programs that don't understand them, but neither file had one.

The bills.inc.php file works just fine on our dev server, but not in production. I don't get it. It should work. Failing that, it should at least log an error to tell me what the heck is going wrong. Any suggestions welcome.

EDIT:

For the record, I have turned on ini_set('display_errors', 1); and set error_reporting(E_ALL) for debug purposes. No errors are reported. If I run the second line, I get a white screen.

EDIT:

It turns out there was a typo in my call to ini_set, and so errors weren't actually displaying. Once I fixed that it turned out to be a normal parse error. My apologies for posting too soon.

Will Martin
  • 3,874
  • 1
  • 22
  • 37
  • 2
    Possible duplicate of [How do I get PHP Errors to display?](http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) – Chris Aug 15 '16 at 17:01
  • 1
    `require` and `include` aren't functions. you can't depend on their return values. they can/will return false if the include/require failed, but they can ALSO return whatever value is explicitly returned by the code being loaded - and you can NOT tell the difference between "false because of failure" and "false because something did return false". And in any case if require fails, it kills the script. there'll never be anything returned anyways. – Marc B Aug 15 '16 at 17:05
  • I have edited the question to respond to the error display comment. @MarcB - ordinarily, I wouldn't test the value of `require_once` at all. That was strictly for testing purposes. – Will Martin Aug 15 '16 at 17:07
  • Oh, FFS. There was a typo in my call to `ini_set()`, so errors weren't really turned on. Once I fixed that it was a parse error. Bah! I apologize for posting too soon. – Will Martin Aug 15 '16 at 17:21

0 Answers0