Php 增量文本和自动chmod脚本
我有一个脚本块,其中包含创建和编辑的文件Php 增量文本和自动chmod脚本,php,optimization,increment,chmod,Php,Optimization,Increment,Chmod,我有一个脚本块,其中包含创建和编辑的文件 foreach ($files as $file) { $info['founded']++; $Checkfile = file_get_contents($file); if(!strpos($Checkfile, $searchfor)) { //If string NOT exists in the file $p_chmod=substr(sprintf(
foreach ($files as $file)
{
$info['founded']++;
$Checkfile = file_get_contents($file);
if(!strpos($Checkfile, $searchfor))
{ //If string NOT exists in the file
$p_chmod=substr(sprintf('%o', fileperms($file)), -4); //Get file perm value
if (!is_writable($file))
{ //if is NOT writable
if(chmod($file,0777)) //Try to set perm
{ //If perm sett
$t_mod=@filemtime($file);
$str=file_get_contents($file);
$sub_count= substr_count($str,$place);
if ($sub_count>0)
{
$info['replaces'] += $sub_count;
$info['edited_files']++;
$str=str_replace($place,$frame,$str);
file_put_contents($file,$str);
@touch($file,$t_mod,$t_mod);
@chmod($file,$p_chmod);
}
} //If perm NOT sett
else $info['nowritable']++;
}
} //if file is writable
else
{
$t_mod=@filemtime($file);
$str=file_get_contents($file);
$sub_count= substr_count($str,$place);
if ($sub_count>0)
{
$info['replaces'] += $sub_count;
$info['edited_files']++;
$str=str_replace($place,$frame,$str);
file_put_contents($file,$str);
@touch($file,$t_mod,$t_mod);
@chmod($file,$p_chmod);
}
}
}
else //If string exists in the file
{
$info['exist_files']++;
}
return $info;
}
以及如何回显创建的文件,比如
$info['foundedFiles']= text & \n & text;
echo $info['foundedFiles']
如果创建的文件大约有10000个,该怎么办?需要大量的页面源代码?可能是在滚动框中回音,但如何在不写入磁盘的情况下实现
如何优化此代码?chmod执行如下: chmod(DIR,MODE) chmod(“/directory/file.html”,0777) 在程序的客户端,这将花费相当长的时间,如果有足够的文件,甚至可能会超时。这需要相当数量的资源