Reputation: 7647
A very noob question : Does php file_exists($path)
check the sub-directories of $path
??
Is it a disk read intensive processes? Meaning does it increase linearly(polynomial/ exponentially) depending upon number of folders / file in the directory being checked against?
Background info: I am running some file operation scripts on EC2, my read ops keep exponentially increasing, since I started the script. AWS charges $0.11/million I/O requests and costs are increasing quite rapidly :(.
I analysed the code, I think the only part that could cause this sort of increasing performance loss issue is the part of the script checks if the file exists or else downloads it from a S3 bucket, as pretty much everything else is compute/write or a small read ops. I have ten of thousands of files of 3-5 MB each if that is of any relevance. After each cycle the script generates few more files of similar size etc.
EDIT: Correction to clarify Jim's point
EDIT 2: The performance I am asking about is not in terms of time for the script to run, but in terms of number of disk reads, as this charged separately by AWS.
Upvotes: 0
Views: 377
Reputation: 19563
1 I/O is when 1 block is read or written to the disk. Block sizes are often quite small, usually about 4KB. For heavily accessed files, there are often caches involved that can reduce the overall I/O needed to perform the operation.
I think 1 or a combination of the following is happening.
You are underestimating how many files you are copying back and forth. a 3 MB file read or written once in its entirety will probably cost about 750 I/O's
You are exceeding available memory, forcing your system to turn to swap, which is most likely configured to write to the EBS volume. Use free
to see this.
If you are not already doing so, you may want to consider using APC or another opcode cache.
You can also mount your volumes disabling features like mtime and atime (updating modified time and accessed time)
Upvotes: 1
Reputation: 1339
file_exists($path)
does not check sub-sirectories; in order to do this, you would have to write your own function that navigate throught directories.
It does check in the current directory (where the .php file is located), unless you provide an absolute or relative path.
You should (probably want to) use is_file()
or is_dir()
whether you’re checking for a file or a directory, respectively.
And for the performance aspect of file_exists()
(or is_file()
or is_dir()
), they are definitely not intensive functions and I wouldn’t think they are the bottleneck of any php script.
Upvotes: 1
Reputation: 22656
I'm not sure if you mean does file_exists($path)
check subdirectories of path or if it checks subdirectories of the current working directory for path.
In either case the answer is no. $path
is taken simply as a path and the method confirms whether or not that file/directory exists.
Upvotes: 1