Bug #47640 [Com]: Session does not unlock file in /tmp/

From: Date: Wed, 12 Sep 2012 17:56:16 +0000
Subject: Bug #47640 [Com]: Session does not unlock file in /tmp/
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-173377@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=47640&edit=1

 ID:                 47640
 Comment by:         connie at jaygoss dot com
 Reported by:        manuel dot schmitt at manitu dot de
 Summary:            Session does not unlock file in /tmp/
 Status:             Open
 Type:               Bug
 Package:            Session related
 Operating System:   Linux
 PHP Version:        5.2.9
 Block user comment: N
 Private report:     N

 New Comment:

I just encountered this bug on version 5.3.13. The script worked fine for about 
a year, then stopped working for no known reason (no code changes, version 
upgrades, etc.)

This script works:

echo "<br>Flock Test Without Session<br>"; 
$fp = fopen("_order_id.txt", "r+");
if (flock($fp, LOCK_EX)) { 
    /* do an exclusive lock to get an order number */
    $id = fread($fp,filesize("_order_id.txt"));
    $id++;
    echo "<br>Got the lock, id is now $id";
    ftruncate($fp, 0); /* truncate file */
    rewind($fp); /* reset pointer */
    fwrite($fp, $id); /* write new order id */
    flock($fp, LOCK_UN); /* release the lock */
} else {
    echo "Couldn't get the lock"; 
}

However, if I put the same code inside a session, it fails on my live site, but 
still works fine in my localhost (version 5.3.8):

session_start();
echo "<br>Flock Test With Session<br>"; 
$fp = fopen("_order_id.txt", "r+");
if (flock($fp, LOCK_EX)) { 
    /* do an exclusive lock to get an order number */
    $id = fread($fp,filesize("_order_id.txt"));
    $id++;
    echo "<br>Got the lock, id is now $id";
    ftruncate($fp, 0); /* truncate file */
    rewind($fp); /* reset pointer */
    fwrite($fp, $id); /* write new order id */
    flock($fp, LOCK_UN); /* release the lock */
} else {
    echo "Couldn't get the lock"; 
}
session_destroy();


Previous Comments:
------------------------------------------------------------------------
[2012-09-12 03:14:57] aharvey@php.net

Explanation provided separately, since it's not relevant to this bug. Bug reopened.

------------------------------------------------------------------------
[2012-09-12 03:10:26] laruence@php.net

...maybe it's chagned by the reporter self, no action history log in the changes 
tab

------------------------------------------------------------------------
[2012-09-11 20:39:24] kriscraig@php.net

Could somebody explain why the status was changed to "Not a bug?"  I'm not seeing 
anything in the comments to indicate why that edit was made.  Looks like a real 
bug to me and everything else seems to check-out, so I'm assuming that was an 
error given the lack of an explanation.

I'm re-opening this with "Feedback" status.  If you're the one who closed this 
(the edit history is empty), please post a comment explaining your reasoning.  
Thanks!

------------------------------------------------------------------------
[2012-05-27 01:04:29] bugs dot php dot net at jrs-s dot net

I worked around this problem by simply moving sessions from file storage to 
memcache.

session.save_handler = memcache
session.save_path = "tcp://serv01:11211,tcp://serv02:11211,tcp://serv03:11211"

An application pool that had been creeping up to MaxCli (900 children apiece, in 
this case) within a couple hours of a restart due to this FLOCK issue settled 
down and has now been running happily for several days on fewer than 150 
children per server.  I highly recommend just NOT USING php's file based session 
storage in the first place, because of exactly this issue.

------------------------------------------------------------------------
[2012-02-01 19:50:15] pio at rdl dot pl

Hello !

Is there any news with this issue ?

Piotr

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=47640


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=47640&edit=1


Thread (22 messages)

« previous php.bugs (#173377) next »