0

Is there any circumstance in which the same $_SERVER['REQUEST_URI'] should open two different PHP files?

I'm not using mod_rewrite, just Apache virtual hosts and Alias pointers to the target directories in which my PHP files live, but I'm seeing something completely mysterious to me. Two identical requests 1/2 hour apart with no intervening changes to anything (Apache config, FS etc.) have different files loaded with the same REQUEST_URI:

In utilupdate.php I have:

error_log("Loading ".__FILE__." <= $_SERVER['REQUEST_URI']@$_SERVER['SERVER_NAME']);

From error.log:

[Mon Jul 07 17:30:01.224430 2014] [:error] [pid 18928] [client 23.253.161.240:54571]
 Loading /var/www/html/stage/utilupdate.php <= /dev/utilupdate.php@api.nugg.co
[Mon Jul 07 17:30:01.224510 2014] [:error] [pid 19518] [client 23.253.161.240:54572]
 Loading /var/www/html/stage/utilupdate.php <= /stage/utilupdate.php@api.nugg.co

From access.log:

23.253.161.240 - - [07/Jul/2014:17:30:01 +0000] "GET /stage/utilupdate.php HTTP/1.1" 200 1263 /var/www/html/stage/utilupdate.php 700653
23.253.161.240 - - [07/Jul/2014:17:30:01 +0000] "GET /dev/utilupdate.php HTTP/1.1" 200 1263 /var/www/html/dev/utilupdate.php 701516

Half an hour prior, it was also wrong but reversed:

[Mon Jul 07 16:30:01.680617 2014] [:error] [pid 15566] [client 23.253.161.240:54257] Loading /var/www/html/dev/utilupdate.php <= /dev/utilupdate.php@api.nugg.co
[Mon Jul 07 16:30:01.686350 2014] [:error] [pid 15567] [client 23.253.161.240:54261] Loading /var/www/html/dev/utilupdate.php <= /stage/utilupdate.php@api.nugg.co

23.253.161.240 - - [07/Jul/2014:16:30:01 +0000] "GET /stage/utilupdate.php HTTP/1.1" 200 1261 /var/www/html/stage/utilupdate.php
23.253.161.240 - - [07/Jul/2014:16:30:01 +0000] "GET /dev/utilupdate.php HTTP/1.1" 200 1261 /var/www/html/dev/utilupdate.php

Looks to me like something's wrong with caching somewhere, but I don't know where to even start. Could this have something to do with xcache or opcache?

leei
  • 139
  • 5

1 Answers1

0

I've managed to track down the bug and it was illustrative, so I think I need to share.

When upgrading from PHP 5.4 to 5.5, the OpCache was added as a default "extension" and with my deployment system, automatically on. Now, I had previously been using XCache to solve the same problem, so now I had (without initially being aware of it) two separate opcode caches operating on my PHP.

It seems that there was some critical interaction between them such that two separate HTTP queries that mapped to two different but identical PHP files (in our cases in the deployed system and a staged testing deployment) were being executed with the same __DIR__ and __FILE__ values initialized. Big problems for relative loads and class autoloader.

So, lesson learned, make sure that you haven't accidentally enabled both OpCache and XDebug opcode cache at the same time.

leei
  • 139
  • 5