复制代码 代码如下:
php
/**
* 写入数据
* @param [string] $path [文件路径]
* @param [string] $mode [文件打开模式]
* @param [string] $data [数据]
* @return [bool]
*/
function writeData($path, $mode, $data){
$fp = fopen($path, $mode);
$retries = 0;
$max_retries = 100;
do {
if ($retries > 0) {
usleep(rand(1, 10000));
}
$retries += 1;
}while (!flock($fp, LOCK_EX) and $retries if ($retries == $max_retries) {
return false;
}
fwrite($fp, $data."\r\n");
flock($fp, LOCK_UN);
fclose($fp);
return true;
}
/**
* 读数据
* @param [string] $path [文件路径]
* @param [string] $mode [文件打开模式]
* @return string
*/
function readData($path,$mode){
$fp = fopen($path, $mode);
$retries = 0;
$max_retries = 100;
do {
if ($retries > 0) {
usleep(rand(1, 10000));
}
$retries += 1;
}while (!flock($fp, LOCK_SH) and $retries if ($retries == $max_retries) {
return false;
}
$contents = "";
while (!feof($fp)) {
$contents .= fread($fp, 8192);
}
flock($fp, LOCK_UN);
fclose($fp);
return $contents;
}
writeData('D:/webServer/demo.txt','a+','this is a demo');
echo readData('D:/webServer','r+');
Delphi 7应用编程150例 CHM全书内容下载,全书主要通过150个实例,全面、深入地介绍了用Delphi 7开发应用程序的常用方法和技巧,主要讲解了用Delphi 7进行界面效果处理、图像处理、图形与多媒体开发、系统功能控制、文件处理、网络与数据库开发,以及组件应用等内容。这些实例简单实用、典型性强、功能突出,很多实例使用的技术稍加扩展可以解决同类问题。使用本书最好的方法是通过学习掌握实例中的技术或技巧,然后使用这些技术尝试实现更复杂的功能并应用到更多方面。本书主要针对具有一定Delphi基础知识
0
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号