Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

More than once I have ran into this issue: I have a cache file that is automatically generated by PHP. It contains some generated PHP code. However for some reason the file cannot be read and parsed by PHP. These are the symptoms:

  • File actually exists on file system. Using Terminal you can navigate to the file, view its contents (which are fully intact), etcetc.
  • PHP file_exists() will report that the file exists...which is correct since it does :)
  • Then I include() the file. But when actually parsing the file, PHP will just consider it an empty file. No fatal error, just no PHP code actually executed. Again, its as if the file was completely empty (which I assure you, it is not)...
  • It is not a permissions issue. Permissions are set as needed.
  • Workaround: open the file in Terminal via 'nano' or some other text editor and just save it to the disk again. After that (despite no changes to the content) PHP will run it just fine...
  • As a clarification, I'd like to add that this happens rarely, but frequently enough to be a problem. And even when it does, there are hundreds of other similar files on the same system that work without a problem...

If this were an issue affecting only my own scripts, I would consider that there must be a bug in the way I generate the PHP code. But no, the issue has occurred more than once when deploying to a server (usually from Beanstalk repository via FTP).

The issue has been present on various servers, Debian and Ubuntu running Zend Community Server. Any ideas? One that crossed my mind was opcode cache-ing (part of Zend Server CE)...could it be that an empty version of the file is cached if it is requested while the write operation is still in progress?

share|improve this question
    
You may post your PHP loop for file reading, it seems that PHP can't read all pointers on your file or your PHP code is not correct. –  Dr I Nov 22 '12 at 15:32
    
Since it works after I save the file with the same content (no change) the code has to be correct. As for reading - since it is generated PHP code - I simply include() the file. If there are code errors in the file, warnings/errors are reported properly, so this is not the issue in this case. –  Aron Nov 22 '12 at 15:37
    
Your assertion is not totally true. I did already had a file generated with PHP but this one had a coupled Access permission problem mixed with a loop error, but none of the both reported me an error. Basically, when you open the file, you change the inode metainformations and other statements of the file. What is the userID used by your webserver to create the file? What is the userID that you use to Open the file? Do you perform a for each loop to read your file? Do you use a PCL method? –  Dr I Nov 22 '12 at 15:42
    
I don't read the file line by line. I use include(). –  Aron Nov 22 '12 at 15:50
    
I know there can be issues with error reporting but that is not the case here, since errors are reported in the case that there are errors. There are none here, since an empty file is valid according to PHP. –  Aron Nov 22 '12 at 15:51
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.