FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Prevent unlink(...) warning
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Prevent unlink(...) warning [message #176030 is a reply to message #176027] Thu, 17 November 2011 17:42 Go to previous messageGo to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma:
Senior Member
El 17/11/2011 16:04, Simon escribió/wrote:
> I am having some race condition issues on my server when trying to
> delete a file.
>
> //
> function my_unlink( $filename )
> {
> // remove the old file
> clearstatcache(TRUE, $filename);
> if (file_exists($filename))
> {
> @unlink($filename);
> }
> else
> {
> return true;
> }
>
> clearstatcache(TRUE, $filename);
> return (!file_exists($filename)); // check it was deleted.
> }
> //
>
> In some cases I get
>
> unlink(/home/xxx/public_html/temp/yyy.zz) [function.unlink]: No such
> file or directory
>
> How can I prevent the warning?


I can think of three possible approaches:

1. Try out flock() and find out whether it prevent other processes from
removing the file and whether it allows _you_ to remove it.

2. Write a custom error handler and see if you can convert the warning
into ErrorException. If you succeed, you can then try...catch around the
unlink() call.

3. Keep the @ and live with it. I hate the error suppression operator as
much as anyone but there're situations where trying to do without it is
just not worth the effort.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Embedding HTML Within a PHP Statement
Next Topic: Re: comp.lang.php forum
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 11:16:56 GMT 2024

Total time taken to generate the page: 0.05923 seconds