08c09-1.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 33 行

PHP
33
字号
<?php// Open the file to append data to itif (!($fp = fopen('data.log', 'a'))) {	die ('ERROR: Could not open file!');}// At this point we need to remove the ability for a user to abortignore_user_abort(true);// Now attempt to get an exclusive lockif (!(flock($fp, LOCK_EX))) {	die('ERROR: Could not get exclusive lock!');}// We now have the lock, To make sure that another file didn't// write data into this file while we waited for the lock, seek// to the end of the file:fseek($fp, 0, SEEK_END);// Now we can write our data:fwrite($fp, 'A Random Number: ' . rand() . "\n");// Close the file - Which also releases the lockfclose($fp);// And now allow a user abort again:ignore_user_abort(false);// Now echo out our file contents so that we can see what happened:echo '<pre>';readfile('data.log');echo '</pre>';?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?