You are here: flock - will this work? « PHP SQL « IT news, forums, messages
flock - will this work?

Posted by paul on 09/06/05 02:00

Hi,

If more than one user clicks the submit button at the same time can I use
flock to ensure that all the data gets written to the file? Is the following
code correct?

Thanks,

Paul
=======================
// open for writing
$fp = fopen($filename, "a") or die("Unable to open file, please try again
later.");

// wait for unlock if it's busy
while(TRUE) // do forever
{
if( flock($fp, LOCK_EX) )
{
// write to file
fwrite($fp, $first);
fwrite($fp, $last);
fwrite($fp, $phone);

// unlock file
flock($fp, LOCK_UN);
break; // done, get out of loop
}
sleep(1); // wait a second and try again
}

// close file
fclose($fp);
============================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация