Re: oops! flock() not work

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 22, 2006 7:11 am, n.g. wrote:
> flock() with LOCK_NB not work under ,
> nor does fopen() with 'x' mode,
> my php is compiled as an apache module, and apache is running in
> prefork mpm.
> php version is 5.1.2
>
> my code is
>
> <?php
> $haslock=0;
> if($lock=fopen('LOCK','w')){

This would work ONLY if the directory containing your PHP script on
your website was world-writable.

*THAT* would be particularly *BAD*!!!

So you need to specify a php-writable (world-writable, in most cases)
directory for your 'LOCK' file to live in, with something like:
'/var/share/your_application_name/LOCK'

>    if(flock($lock,LOCK_EX|LOCK_NB))$has_lock=1;
> }
>
> if($has_lock){
>   //do something which should always be only one process
> }
> ?>
>
> or
>
> <?php
> $has_lock=0;
> $lock=fopen('LOCK','x');
> if($lock)$has_lock=1;
> if(has_lock){
>   // do something
> }
>
> both of them wont work.
> however cli mode works well.
>
> any clue?
>
> TIA.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux