Re: [PHP] Error Reporting for file commands
On Tue, July 25, 2006 10:32 am, James Nunnerley wrote: We've created a file manager which allows users to access their web space on a server. It's working brilliantly, except that it would seem there are some caching issues, either by the system cache or the web server cache that are causing us a headache. When the script tries to delete a file, we always check (using file_exists) to see whether the file exists before it's deleted. But if some other process is deleting that file, you have a race condition. It's pointless to check before you delete, really -- You simply have to use the result from unlink() to know if it worked or not. The check comes back true, but the unlink then fails, saying no file or directory there! We've tried turning off all errors (using error_reoprting(0) ) but this would seem to have little difference in the error - it still comes back with a failure. Any time the solution is error_reporting(0) then you are doing something fundamentally wrong. We are using our own error handling, but before the command is carried out, there is this 0 call... If you use set_error_handler(), it is called regardless of error_reporting() settings. http://php.net/set_error_handler Does anyone know how we can stop these errors? I would suggest that you make sure that you are using the FULL PATH to unlink() -- Relying on any kind of relative path is just going to get you into trouble. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Error Reporting for file commands
We've created a file manager which allows users to access their web space on a server. It's working brilliantly, except that it would seem there are some caching issues, either by the system cache or the web server cache that are causing us a headache. 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! We've tried turning off all errors (using error_reoprting(0) ) but this would seem to have little difference in the error - it still comes back with a failure. We are using our own error handling, but before the command is carried out, there is this 0 call... Does anyone know how we can stop these errors? Cheers Nunners -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Error Reporting for file commands
You could try prefixing the unlink function call with an @: if (file_exists($fn)) { @unlink($fn); } The @ should suppress any errors. jon James Nunnerley wrote: We've created a file manager which allows users to access their web space on a server. It's working brilliantly, except that it would seem there are some caching issues, either by the system cache or the web server cache that are causing us a headache. 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! We've tried turning off all errors (using error_reoprting(0) ) but this would seem to have little difference in the error - it still comes back with a failure. We are using our own error handling, but before the command is carried out, there is this 0 call... Does anyone know how we can stop these errors? Cheers Nunners -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: Spam:[PHP] Error Reporting for file commands
[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? You'll also see there are quite a lot of clearstatcache - that was another attempt to sort this problem out! 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RE: Spam:[PHP] Error Reporting for file commands
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php