PHP multiple threads reading, writing a file at the same time

By XiaoXin
A Bit Randomly

JSON A lightweight data interchange format. It is based on a subset of ECMAScript. JSON uses a text format that is completely language-independent but also uses conventions similar to the C language family (including C, C+... Read What are the characteristics of json format data?

Main Contents

PHP multiple threads reading, writing a file at the same time

$fp = fopen("/tmp/lock.txt","w+");
if (flock($fp , LOCK_EX)) { // Exclusive lock
  fwrite($fp , "Write something here\n");
  flock($fp , LOCK_UN); // release lock
} else {
  echo "Couldn't lock the file!" ;


Please Share This Article Thank You!

Parts of Top Latest PHP Interview Questions And Answers For Experienced
PHP session usage instead of a cookie, make session expiration and the corresponding function

Pass the value through the url, and attach the session id to the url (disadvantage: there cannot be pure static pages in the entire site, because the session id of pure static pages will not continue to be passed to the ne...

What is PHP heredoc used for?

Heredoc is generally not described in detail in formal PHP documentation and technical books. It is a Perl-style string output technique. Using heredoc technology can realize the quasi-separation of interface and code, suc...