top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

PHP flock() implemention at the process level?

0 votes
799 views

On http://php.net/manual/en/function.flock.php is written a warning:

" On some operating systems flock() is implemented at the process level. When using a multi-threaded server API like ISAPI you may not be able to rely on flock() to protect files against other PHP scripts running in parallel threads of the same server instance! ... "

I do not understand what means that flock is implemented at the process level. Does it mean following?:
If in one process in one thread is called flock($fp, LOCK_EX) , in the second thread flock($fp, LOCK_EX) won't block. $fp are the same in both calls and flock(.) in the second thread is called before flock(., LOCK_UN) from the first thread.

I made a test on Windows 2008 R2, ISS, php 5.3 FastCGI. I tried even 4 concurrent requests and I think it is working (flock blocks as expected). I found out that for each GET request it was created a separate process php-cgi.exe. So the assumption for this warning even will not occur.

I made a second test on Windows 2008 R2, Apache, php 5.3 as a module. In this scenario flock also works. And all GET requests were handled by the same process.

Can someone confirm that it is safe to use flock on Windows/IIS+FastCGI and Windows/Apache(multithread) + php(module) ?

posted Jul 15, 2014 by Mandeep Sehgal

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
+1 vote

I have 5 SELECT for Department, Manager, supervisor, Group Leader and Employees
I want to every SELECT list narrow down for an upper SELECT. For example, once user select Department then all Manager, Supervisor, Group Leader and Employee list will be narrow down by department and same for manager and supervisor and so on.

I can use iframe or jQuery to do every level, but it needs to call iframe or jQuery to 5 levels. I would like to know are there any better way to handle this situation.

+3 votes

Say I have sent a command to a process using the fwrite command something like

...
while (true) {
 switch (expect_expectl($stream, $cases)) {
 case "ls":
 fwrite($stream, "ls -aln");
 break;
..

Is there a way I can save the output from that process to a variable ?

...