Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #3817 > unrolled thread
| Started by | Simon <bad@example.com> |
|---|---|
| First post | 2011-11-17 17:04 +0200 |
| Last post | 2011-11-17 13:54 -0500 |
| Articles | 6 — 4 participants |
Back to article view | Back to comp.lang.php
Prevent unlink(...) warning Simon <bad@example.com> - 2011-11-17 17:04 +0200
Re: Prevent unlink(...) warning The Natural Philosopher <tnp@invalid.invalid> - 2011-11-17 15:18 +0000
Re: Prevent unlink(...) warning Simon <bad@example.com> - 2011-11-17 19:21 +0200
Re: Prevent unlink(...) warning The Natural Philosopher <tnp@invalid.invalid> - 2011-11-17 18:29 +0000
Re: Prevent unlink(...) warning "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-11-17 18:42 +0100
Re: Prevent unlink(...) warning Jerry Stuckle <jstucklex@attglobal.net> - 2011-11-17 13:54 -0500
| From | Simon <bad@example.com> |
|---|---|
| Date | 2011-11-17 17:04 +0200 |
| Subject | Prevent unlink(...) warning |
| Message-ID | <9ikm3eFih4U1@mid.individual.net> |
Hi,
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?
Thanks
Simon
[toc] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2011-11-17 15:18 +0000 |
| Message-ID | <ja38jj$au4$1@news.albasani.net> |
| In reply to | #3817 |
Simon wrote:
> Hi,
>
> I am having some race condition issues on my server when trying to
> delete a file.
>
what makes you think its a race condition?
> //
> 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.
> }
> //
>
Why do you care about the stat cache?
> 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?
>
Why prevent it at all?
As long as the file is not there when you are finished - why not just
unlink it anyway?
> Thanks
>
> Simon
>
[toc] | [prev] | [next] | [standalone]
| From | Simon <bad@example.com> |
|---|---|
| Date | 2011-11-17 19:21 +0200 |
| Message-ID | <9iku5gFi18U1@mid.individual.net> |
| In reply to | #3818 |
On 2011/11/17 05:18 PM, The Natural Philosopher wrote:
> Simon wrote:
>> Hi,
>>
>> I am having some race condition issues on my server when trying to
>> delete a file.
>>
>
> what makes you think its a race condition?
A guess really,
If I do:
...
if (file_exists($filename))
{
and followed by
...
@unlink($filename);
}
And that gives me a
unlink(/home/xxx/public_html/temp/yyy.zz) [function.unlink]: No such
file or directory
The something between file_exists(...) and @unlink(...) must have
removed the file.
Either that or one of the two functions is not working as expected.
>
> Why do you care about the stat cache?
>
As per the doc, http://php.net/manual/en/function.clearstatcache.php, to
make sure that file_exists($filename) does return a cached value.
>>
>> How can I prevent the warning?
>>
> Why prevent it at all?
>
> As long as the file is not there when you are finished - why not just
> unlink it anyway?
>
Because the warnings fill my logs and I aim for no warnings at all.
Simon
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2011-11-17 18:29 +0000 |
| Message-ID | <ja3jqa$75v$1@news.albasani.net> |
| In reply to | #3819 |
Simon wrote:
> On 2011/11/17 05:18 PM, The Natural Philosopher wrote:
>> Simon wrote:
>>> Hi,
>>>
>>> I am having some race condition issues on my server when trying to
>>> delete a file.
>>>
>>
>> what makes you think its a race condition?
>
> A guess really,
>
> If I do:
> ...
> if (file_exists($filename))
> {
>
> and followed by
> ...
> @unlink($filename);
> }
>
> And that gives me a
>
> unlink(/home/xxx/public_html/temp/yyy.zz) [function.unlink]: No such
> file or directory
>
> The something between file_exists(...) and @unlink(...) must have
> removed the file.
> Either that or one of the two functions is not working as expected.
>
Hmm..what else CAN be deleting that file (unless you are doing the same
thing twice)?
>>
>> Why do you care about the stat cache?
>>
>
> As per the doc, http://php.net/manual/en/function.clearstatcache.php, to
> make sure that file_exists($filename) does return a cached value.
>
>>>
>>> How can I prevent the warning?
>>>
>> Why prevent it at all?
>>
>> As long as the file is not there when you are finished - why not just
>> unlink it anyway?
>>
>
> Because the warnings fill my logs and I aim for no warnings at all.
>
Well, that's reasonable..;-)
> Simon
[toc] | [prev] | [next] | [standalone]
| From | "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> |
|---|---|
| Date | 2011-11-17 18:42 +0100 |
| Message-ID | <ja3h12$jrj$1@dont-email.me> |
| In reply to | #3817 |
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
--
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2011-11-17 13:54 -0500 |
| Message-ID | <ja3l8u$hi2$1@dont-email.me> |
| In reply to | #3817 |
On 11/17/2011 10:04 AM, Simon wrote:
> Hi,
>
> 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?
>
> Thanks
>
> Simon
>
In addition to what Álvaro said, if you're doing a lot of this in your
scripts, I would suspect a database may be a better solution.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web