note 114928 added to function.flock
| From: | tom dot vom dot berg at online dot de | Date: | Mon, 28 Apr 2014 18:46:51 +0000 |
| Subject: | note 114928 added to function.flock | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-199364@lists.php.net to get a copy of this message | ||
if you are used to reply with qualified error messages by using "track_errors = 1" and
$php_errormsg, flock() will nark you, if you use LOCK_NB .
If flock() fails due to LOCK_NB $php_errormsg will not be created and filled with an error message
like 'could not lock file, file already locked'.
You can use some little workaround which does also on WIN:
#---------------------------------
GLOBAL $MYERRORMSG;
function some_file_operations($filename)
{
GLOBAL $MYERRORMSG;
# ...
# ...
if (! @flock($fh, LOCK_SH | LOCK_NB, $wb))
{
if (!isset($php_errormsg)) $php_errormsg = 'could not lock file, file already locked';
$MYERRORMSG = $php_errormsg;
return false;
}
}
#--------------------------------
In case of fail $MYERRORMSG now will hold a qualified error message
----
Server IP: 87.106.1.137
Probable Submitter: 80.140.115.157
----
Manual Page -- http://php.net/manual/en/function.flock.php
Edit -- https://master.php.net/note/edit/114928
Del: integrated -- https://master.php.net/note/delete/114928/integrated
Del: useless -- https://master.php.net/note/delete/114928/useless
Del: bad code -- https://master.php.net/note/delete/114928/bad+code
Del: spam -- https://master.php.net/note/delete/114928/spam
Del: non-english -- https://master.php.net/note/delete/114928/non-english
Del: in docs -- https://master.php.net/note/delete/114928/in+docs
Del: other reasons-- https://master.php.net/note/delete/114928
Reject -- https://master.php.net/note/reject/114928
Search -- https://master.php.net/manage/user-notes.php