我有两段php代码。第一段代码是在硬盘上创建一个folder,然后用system调用linux的cp命令copy一些文件到这个folder。
第二段代码是更新后台mysql数据库的一些表。
两段代码分开执行,都没有问题。放在一块就死活不行,报错是前台extjs报出来的,说是与mysql通信错误,mysql的log也看不出什么问题。只能肯定不是语法,变量赋值啥的问题。
求高人们给点思路。
另外,在apache的log中也没有看出什么有用的信息
第二段代码是更新后台mysql数据库的一些表。
两段代码分开执行,都没有问题。放在一块就死活不行,报错是前台extjs报出来的,说是与mysql通信错误,mysql的log也看不出什么问题。只能肯定不是语法,变量赋值啥的问题。
求高人们给点思路。
另外,在apache的log中也没有看出什么有用的信息
$dir='/home/automation/wats/script/'.$productName.'/'.$projectName;
if(!is_dir($dir)){
$res=mkdir($dir);
chmod($dir,0777);
if($res){
//$msg=$msg.'add the project folder into the disk automatically!<br/>';
$sourcedirectory='/home/automation/wats/script/'.$productName.'/'.$original_projectname;
//$copycommand='cp -r '.$sourcedirectory.'/* '.$dir;
$copycommand="cp -r $sourcedirectory/* $dir";
$lastline=system($copycommand,$commandresult); if(!$commandresult){
$msg=$msg.'Copy scripts files successfully!<br/>';
}else{
$msg=$msg.'Fail to copy scripts files!<br/>';
}
}else{
$msg=$msg.'FAIL to add the project folder into the disk!Please check it in the disk!';
}
}else{
$msg=$msg.'the folder['.$dir.'] has already existed in the disk!FAIL to create!';
}
第二段php for($j=0;$j<count($selectoriginalscriptresult);$j++){
$data_tempscript['originalid']=$selectoriginalscriptresult[$j]['id'];
$data_tempscript['originalname']=$selectoriginalscriptresult[$j]['name'];
$data_tempscript['copyid']=$selecttargetscriptresult[$j]['id'];
$data_tempscript['copyname']=$selecttargetscriptresult[$j]['name'];
//$temp_scriptresult=$temp_script->add($data_tempscript);
$datastring=$datastring.'('.$data_tempscript['originalid'].",'".$data_tempscript['originalname']."',".$data_tempscript['copyid'].",'".$data_tempscript['copyname']."'),";
}
$temp_scriptsql="insert into `temp_script` values $datastring";
//echo $temp_scriptsql;
$copyproject->query($temp_scriptsql);
就怕这两段代码上了之后更乱,嘿嘿。
请高人指教
现在我主要是担心:
两部分代码都要执行的时间稍长,大概各需20秒左右,这会不会造成php或者mysql连接有问题?
20秒太长了?我设置过php.ini中的max_execution_time为300,没解决这个问题
还有别的办法可以试试吗?
超时是默认的8小时
mysql的链接是通过thinkphp的框架来做的,不是每次都重新连接的。
$cmd = "/usr/bin/php 文件路径/batch.php"; //通过php命令去执行文件操作
$rt = system( $cmd . ' >> /var/log/aa/aa.log &', $rt2);在下面继续你的mysql操作.这样子,上面的文件操作可以转入后台去执行.而不影响你下面的程序.