1

我想在后台运行代码..我想要这个同时下载需要大量时间的巨大报告..我已经浏览了几乎所有的谷歌网站,但仍然无法找到答案..我实际上卡住无法进一步移动..

用于在 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 代码在后台运行。任何帮助,将不胜感激

4

1 回答 1

0

要在后台运行 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 结果输出到一个文件中,在工作完成时设置一些标志,然后在另一个脚本中检查结果是否准备好并为用户提供指向该文件的链接。

于 2013-11-11T06:27:39.873 回答