You are here: Re: flock won't non-block at all « PHP Programming Language « IT news, forums, messages
Re: flock won't non-block at all

Posted by LetsSurf on 09/22/06 08:27

I think you need to open the file with w+ e.g. $fp = fopen("foo.txt",
"w+");

Give it ago see what happends, I might be wrong.

sven.holcombe@gmail.com wrote:
> Hi there,
>
> I'm trying to just prevent multiple instances of a script running.
>
> I would have thought that the following code would do this for me.
>
> <php
> $fp = fopen("foo.txt", "w");
> flock($fp, LOCK_EX + LOCK_NB) or die ("Could not get lock!\n");
> echo "Got lock!\n";
> sleep(10);
> flock($fp, LOCK_UN);
> ?>
>
> The first script to run would obtain the lock on the file, and would
> execute.
> Any other scripts would fail immediately (because of my non-blocking
> LOCK_NB).
>
> But it seems that ALL of my scripts just wait, and ALL of them end up
> printing "Got lock!"
>
> Can anyone help me out?
>
> I am on winXP with php5.
>
> Cheers,
> Sven.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация