php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48321 flock() blocks within function regardless of operation
Submitted: 2009-05-18 22:15 UTC Modified: 2009-05-21 20:05 UTC
From: php at alishabeth dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.2.6 OS: Ubuntu 9.04
Private report: No CVE-ID: None
 [2009-05-18 22:15 UTC] php at alishabeth dot com
Description:
------------
Placing flock() calls within a function seems to result in blocking regardless of the operations specified.  The same exact code outside a function behaves correctly.

This bug report wouldn't let me select the PHP version I'm running.  Wasn't an option

Reproduce code:
---------------
http://alishabeth.com/lock-test.php.txt

Reproduced in the following builds:
$ php -v
PHP 5.1.6 (cli) (built: Apr  7 2009 08:00:18) 
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
    with eAccelerator v0.9.5.2, Copyright (c) 2004-2006 eAccelerator, by eAccelerator


$ php -v
PHP 5.2.6-3ubuntu4.1 with Suhosin-Patch 0.9.6.2 (cli) (built: Apr 23 2009 14:37:14) 
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
    with Xdebug v2.0.3, Copyright (c) 2002-2007, by Derick Rethans


Expected result:
----------------
Using the function always blocks

Actual result:
--------------
Flock should behave correctly within the function

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-19 07:37 UTC] lbarnaud@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-05-19 17:29 UTC] php at alishabeth dot com
I'm sorry, building your latest source to test this further is not something I can do.  I'm hopeful that you have enough developers that you can use the test case I provided to reproduce this yourselves.

Thanks
 [2009-05-19 17:44 UTC] lbarnaud@php.net
Can't reproduce on 5.2.9.
 [2009-05-19 17:48 UTC] php at alishabeth dot com
Is anyone able to reproduce on previous versions such as those I've found it on?  

If so should the documentation be updated to note this issue?
 [2009-05-19 22:49 UTC] jani@php.net
This is really simple actually. Move the sleep inside the function and 
it will work the same way as the "inline" version. 

What happens is when you use the function, once the function is run, 
there are no more references pointing to the opened file pointer and 
it's garbage cleaned (and unlocked) before your sleep() call.
 [2009-05-21 19:52 UTC] php at alishabeth dot com
If the file handle and lock are released by the time you get to the sleep() call (after the function invocation) then why does the call to flock() block at all when you call it the second time?  Based on your description it should be available to lock.
 [2009-05-21 20:05 UTC] php at alishabeth dot com
Disregard my last comment, I now see the error, the lock is obtained in both cases with the function call.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 14:01:31 2024 UTC