Re: RE: Spam:[PHP] Error Reporting for file commands
| From: | Jochem Maas | Date: | Tue, 25 Jul 2006 17:38:35 +0000 |
| Subject: | Re: RE: Spam:[PHP] Error Reporting for file commands | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-239775@lists.php.net to get a copy of this message | ||
James Nunnerley wrote:
>> [snip]
>> When the script tries to delete a file, we always check (using
>> file_exists) to see whether the file exists before it's deleted.
>>
>> The check comes back true, but the unlink then fails, saying no file or
>> directory there!
>> [/snip]
>>
>> Could you please post the code you are using to check and unlink the
>> file?
>
> Heres the function - sometimes the scandir fails, sometimes the unlink,
> sometimes the rmdir at the end. They all have @ to try and surpress the
> error, but I think it's a system halt failure - I can only assume?
my mind boggles as to what a 'system halt failure' is. is a system fails to
halt It would suggest that it's still running, and if it *has* halted then any attempt
to run a script (php or otherwise) is futile... maybe I'm missing something. :-)
>
> You'll also see there are quite a lot of clearstatcache - that was another
> attempt to sort this problem out!
a few things:
1. I don't tihnk you need all those clearstatcache() calls .. from the manual:
"Note: This function caches information about specific filenames, so you only need to call
clearstatcache() if you are
performing multiple operations on the same filename and require the information about that
particular file to not be
cached."
2. you might be looking at a user/group permissions problem... maybe start echoing out the
user and/or group owner of the files to see if that correlates with the failures.
3. turn error reporting to full in order to try and determine the problem?
>
> function system_rmdir($dir) {
> $current_error_level = error_level();
> error_reporting(0);
> $dir = $dir."/";
> $dir=str_replace("//", "/", $dir);
> clearstatcache();
> if (is_dir($dir)) {
> $dir_contents = scandir($dir);
> foreach ($dir_contents as $item) {
> clearstatcache();
> if (is_dir($dir.$item) && $item != '.' && $item !=
> '..') {
> system_rmdir($dir.$item.'/');
> } elseif (file_exists($dir.$item) && $item != '.' &&
> $item != '..') {
> @unlink($dir.$item);
> }
> }
> clearstatcache();
> if (is_dir($dir)) {
> @rmdir($dir);
> }
> }
> error_reporting($current_error_level);
> }
>
> Thanks
> Nunners
>