#46197 [Opn->Fbk]: Problems with file_exists() and multiple instances

From: Date: Sun, 26 Oct 2008 19:15:19 +0000
Subject: #46197 [Opn->Fbk]: Problems with file_exists() and multiple instances
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-130139@lists.php.net to get a copy of this message
 ID:               46197
 Updated by:       jani@php.net
-Summary:          Problems with file_exists and multiple instances
 Reported By:      henrique dot grolli at gmail dot com
-Status:           Open
+Status:           Feedback
 Bug Type:         Filesystem function related
 Operating System: *
 PHP Version:      5.2.6
 New Comment:

Is the webserver by any chance threaded?
See also http://php.net/flock for proper locking method.


Previous Comments:
------------------------------------------------------------------------

[2008-10-05 04:17:06] kalle@php.net

I can reproduce this under Windows Vista with Apache 2

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

[2008-09-29 15:12:10] henrique dot grolli at gmail dot com

Description:
------------
Well, better explained when seeing the code.

Not acting as expected via web browser as the both instances execute as
the lock file was not created by another instance but doing it well via
shell console.

Same problem using clearstatcache() function.

Reproduce code:
---------------
// LOCK_FILE was defined to /tmp/test.lock
// creating the lock file
if(file_exists(LOCK_FILE)) {
    echo "ANOTHER INSTANCE RUNNING\n";
    exit(1);
}
else {
    touch(LOCK_FILE);
}

/* any action that takes time*/
echo "running\n";
sleep(5); // simulating slow scripts
echo "done\n";

if(file_exists(LOCK_FILE)) {
    unlink(LOCK_FILE);
}
else {
    echo "I think someone deleted the lock file\n";
}

Expected result:
----------------
To see "running\ndone\n" in one instance, and "ANOTHER INSTANCE
RUNNING\n" if another instance try to execute at the same time.

Actual result:
--------------
Via shell everything works as well but via web browser both instances
run as the lock file doesnt exist.


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


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



Thread (3 messages)

« previous php.bugs (#130139) next »