php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #59724 apc_file_exists
Submitted: 2011-04-19 19:22 UTC Modified: 2012-07-08 04:14 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: luke at webconnex dot com Assigned: chx (profile)
Status: Closed Package: APC (PECL)
PHP Version: 5.3.5 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: luke at webconnex dot com
New email:
PHP Version: OS:

 

 [2011-04-19 19:22 UTC] luke at webconnex dot com
Description:
------------
Perhaps there is a way to do this with apc_exists, but there doesn't seem to be an easy (fast, as in mostly C) way to see if a file already exists in the cache, other than using apc_cache_info (which is a bit crude).

Typically I avoid using functions like file_exists / is_file when including class files (because of the stat). But in some situations it's useful to see if the file exists before including it, especially when you want to avoid a PHP warning.

It would be nice if this function existed, and worked in the same way include/require does (by using include_path).

I would envision something like this:

apc_file_exists($filename, $compile=TRUE);

When $compile is TRUE it tries to find the physical file and compile it. If it exists in the cache or was found and successfully compiled it would return TRUE, otherwise FALSE.

When compile is FALSE it simply checks to see if the file is in the cache. If it is it returns TRUE, otherwise FALSE.

An example of how it would be used:

if(apc_file_exists('/path/to/foo.php')) {
    include('/path/to/foo.php');
}
else {
    print 'The file doesn't exist!';
}

Another possibility is to make file_exists or is_file work with APC :). Currently they return FALSE if the file exists in cache but not on disk.

The best possible use for this is when apc.stat=0, which is awesome when updating production servers (replace the application files, clear cache).


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-08 04:14 UTC] chx@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: chx
 [2012-07-08 04:14 UTC] chx@php.net
http://php.net/manual/en/function.apc-compile-file.php is exactly what you 
described. Except compile is not optional. But without compile it would be just 
file_exists. And, stat is cached.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri May 14 02:01:23 2021 UTC