i want to run code in background..i want this while downloading huge report which takes lot of time.. i have gone through almost all google sites but still m not able to find the answer.. m actually stuck not able to move further..
我想在后台运行代码..我希望这下载巨大的报告,这需要花费大量的时间..我已经通过几乎所有的谷歌网站但仍然无法找到答案..米其实卡住不能进一步移动..
the code m using to download report in xls is
用于在xls中下载报告的代码是
<?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";
}
?>
i want this excel code to run in background. any help would be appreciated
我希望这个excel代码在后台运行。任何帮助,将不胜感激
1 个解决方案
#1
0
To run a PHP file on the background, you must put your code in one file and call the PHP interpreter to run it on the background. On a *nix server, use exec( '/usr/bin/php -f path/to/your/script > /dev/null &' );
. Check the path to the PHP interpreter on your server, it might be something else than /usr/bin/php
, ask your hosting provider if necessary. On a Windows server, use pclose( popen( 'start /b C:\php\php.exe -f path\to\your\script' ) );
(again, assuming that php.exe is in C:\php
).
要在后台运行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中)。
The background process, however, cannot output anything to the user's browser, since it's running on its own. One way to accomplish what you need would be to output the PHP results in a file, set some flag when the job is done, and in another script check if the results are ready and give a link to the file for the user.
但是,后台进程无法向用户的浏览器输出任何内容,因为它自己运行。实现所需要的一种方法是将PHP结果输出到文件中,在作业完成时设置一些标志,在另一个脚本中检查结果是否准备就绪,并为用户提供文件链接。
#1
0
To run a PHP file on the background, you must put your code in one file and call the PHP interpreter to run it on the background. On a *nix server, use exec( '/usr/bin/php -f path/to/your/script > /dev/null &' );
. Check the path to the PHP interpreter on your server, it might be something else than /usr/bin/php
, ask your hosting provider if necessary. On a Windows server, use pclose( popen( 'start /b C:\php\php.exe -f path\to\your\script' ) );
(again, assuming that php.exe is in C:\php
).
要在后台运行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中)。
The background process, however, cannot output anything to the user's browser, since it's running on its own. One way to accomplish what you need would be to output the PHP results in a file, set some flag when the job is done, and in another script check if the results are ready and give a link to the file for the user.
但是,后台进程无法向用户的浏览器输出任何内容,因为它自己运行。实现所需要的一种方法是将PHP结果输出到文件中,在作业完成时设置一些标志,在另一个脚本中检查结果是否准备就绪,并为用户提供文件链接。