File exists but is unreadable by PHP
Posted
by
Aron
on Server Fault
See other posts from Server Fault
or by Aron
Published on 2012-11-22T15:26:51Z
Indexed on
2012/11/22
17:01 UTC
Read the original article
Hit count: 190
php
|filesystems
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?
© Server Fault or respective owner