It is really a bad idea to design a system where locking is required.  Are
you sure there is no way to build the system to not require locking
through the use of atomic updates and such?

Anyway, yes, GET_LOCK is just another query as far as PHP is concerned.
You can pass it to MySQL via mysql_query() and GET_LOCK blocks (you can
give it a timeout) so at the lowest level the retries can be done directly
by GET_LOCK.  But you might want a look like:

  while(true) {
      $res = mysql_query("select GET_LOCK('my_lock',5)");
      if(mysql_result($res,0)) break;
  }

This will keep trying to get the lock forever with each get_lock attempt
blocking for 5 seconds.  You may want to stick in a counter to eventually
give up or just rely on PHP's timeout feature to eventually abort in case
(or should I say when) you back yourself into a deadlock corner.

-Rasmus

 On Fri, 5 Oct 2001, Chip wrote:

> I'm preparing to write a DB app using PHP as the programming interface.  I
> need to be able to lock records at certain points.  I was wondering if the
> following is possible using PHP.
>
> 1.  I want to use the GET_LOCK(str, timeout) function to lock records based
> on the record ID.  Can GET_LOCK be called through PHP??
>
> 2.  If the GET_LOCK fails (Someone else allready has the lock for that
> record), I want to make the PHP code to continue attempting to GET_LOCK
> until it is available.  Can you do events every 5 seconds until success in
> PHP?
>
> THANKS!
>
>
>
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to