| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2012-05-25 00:00 UTC] danny at tibibi dot com
 Description:
------------
I am using php 5.4.1 with APC 3.1.10
You need to give full write permissions to the account running apache on all the files served by apache in order for caching to work. This not good practice.
I have found and fixed the problem in the function apc_restat in apc.c.
hFile = CreateFile(fileinfo->fullpath, GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_FLAG_BACKUP_SEMANTICS, NULL);
should be
hFile = CreateFile(fileinfo->fullpath, GENERIC_READ | GENERIC_EXECUTE, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
Also, the check made to see if the file was opened is not correct.
if (!hFile) {
should be
if (hFile == INVALID_HANDLE_VALUE) {
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 11:00:01 2025 UTC | 
Hi, I cannot confirm this on win7/apache2.2/php5.4 . I've just used a small snippet: <?php function hello() { echo 'hello'; } hello(); in file noaccess.php then removing all the rights for all the users on that file and trying to access it through apache i get: Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Only giving the read permission for the account running apache already makes the file to be executeable by apache+php regardless APC is present or not. Thus, when the PHP code gets executed, APC is in the game by all means. How exactly you see that caching doesn't work? Please try my example wether you can repro it. All the system policies should be checked as your files might inherit some. The best way would be probably to disable inheritance for that file.You're right saying that only the code for includes is affected. That's apc.c in apc_restart. I also get an error when I run this snippet on the windows console on a file with readonly permissions: ============ SNIPPET ======================= #include <windows.h> int main(int argc, char **argv) { HANDLE hf; if (argc < 2) { printf("Usage: createfile path\n"); return 0; } hf = CreateFile(argv[1], GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (hf == INVALID_HANDLE_VALUE) { printf("Could not open %s\n", argv[1]); return 3; } printf("opened %s successfully to write\n", argv[1]); return 0; } ======================= END SNIPPET ========================== BUT, magically there are still no errors when I'm trying to reproduce this with apache. Very strange :) . I just did as you've said - maid an include in the main file with the read permissions only, but it still works in apache+apc. The check with "if(!hFile)" should be "hFile == INVALID_HANDLE_VALUE", that's right. I think there should be more investigation why it doesn't always fail. Could you please provide more detailed error infos?