[英]to run php file in background
我想在后台运行代码..我想在下载庞大的报告时花很多时间..我已经浏览了几乎所有的Google网站,但仍然无法找到答案。.m实际上卡住了,无法进一步移动..
用于在xls中下载报告的代码m是
<?php
include '../dbConnect.php';
$from1='2013-06-01';
$to1='2013-07-01';
$today=date('Y-m-d H:i:s');
$fileName='Outbound_download'.$today.'.xls';
ignore_user_abort(true);
set_time_limit(0);
//echo 'Testing connection handling in PHP';
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$fileName");
$flag = false;
$query="";
$query = "SELECT pendingCustomer.ackNo AS RAF, pendingCustomer.serialNo AS Serial_No, pendingCustomer.phoneNo AS Phone,pendingCustomer.repairStatus as ArrivalStatus,tblRepairQueue.repairStatus as CurrentStatus, pendingCustomer.savedAt AS UpdateRecievedAt, pendingCustomer.updated as Updated, pendingCustomer.status as Status
FROM pendingCustomer,tblRepairQueue
WHERE pendingCustomer.status!='' AND DATE(pendingCustomer.savedAt) BETWEEN '".$from1."' AND '".$to1."' and pendingCustomer.ackNo=tblRepairQueue.ackNo";
$result = mysql_query($query) or die('Error, query failed');
while($row =mysql_fetch_assoc($result)) {
if(!$flag) {
// display field/column names as first row
echo implode("\t", array_keys($row)) ."\r\n";
$flag = true;
}
echo implode("\t", array_values($row)) . "\r\n";
}
?>
我希望这个Excel代码在后台运行。 任何帮助,将不胜感激
要在后台运行PHP文件,必须将代码放在一个文件中,然后调用PHP解释器在后台运行它。 在* nix服务器上,使用exec( '/usr/bin/php -f path/to/your/script > /dev/null &' );
。 检查服务器上PHP解释器的路径,可能是/usr/bin/php
以外的其他路径,如有必要,请询问您的托管服务提供商。 在Windows服务器上,使用pclose( popen( 'start /b C:\\php\\php.exe -f path\\to\\your\\script' ) );
(再次,假设php.exe在C:\\php
)。
但是,后台进程无法自行输出任何内容到用户的浏览器。 一种实现所需功能的方法是将PHP结果输出到文件中,在作业完成时设置一些标志,并在另一个脚本中检查结果是否准备就绪,并为用户提供指向文件的链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.