为什么使用AJAX下载文件会冻结整个PHP Web服务器



我的情况是:

Debian Linux上,我想"绑定"两种报告技术,PHP-Reports使用JSReport

PHP-Reports允许我获得仅使用SQLJSReport的数据和关联的子计算机,允许我精确地使用HTML格式化报告,并在完成一旦完成。

问题是:我希望能够自动保存报告数据文件以在JSReport上获取。

为了做到这一点,我对PHP-Reports来源进行了一些修改:

我使用 jQuery绑定在每一个链接上单击一个 Ajax脚本,该脚本在标签的href上下载。

这是JS部分:

$(".report_link").each(function() {
   $( this ).bind('click', function() {
      $.ajax({
         url: "/user/ajax/save_a_file.php",
         type: 'GET',
         data: "url=" + $( this ).attr("href"),
         // Ajax needs synchronous execution in this case
         async:false,
         success: function(result) {
            alert("Resultat requête AJAX:" + result);
         },
         error: function(xhr, ajaxOptions, thrownError) {
            console.log("AJAX -> Erreur " + xhr.status + ": " + thrownError);
            console.log("WBREPORT -> Error : can not save file");
         }
      });
   });
});

现在我的ajax文件:

 $complete_url = "";
 $starting_date = "";
 $ending_date = "";
 $url = "";
 if(null !== $_GET['url'])// && null !== $_GET['macros'])
 {
    $url = $_GET['url'];
    if (null !== $_GET['macros'])
    {
       $macros = $_GET['macros'];
       if (null !== $macros['date']['start'])
          $url .= '&macros[date][start]=' . urlencode($macros['date']['start']);
       if (null !== $macros['date']['end'])
          $url .= '&macros[date][end]=' . urlencode($macros['date']['end']);
    }
 }
 $filedir = "/var/www/wbreport/user/data/residents/";
 $report_name = "test.json";
 $report_filepath = $filedir . $report_name;
 $ch = curl_init();
 curl_setopt ($ch, CURLOPT_URL, $url);
 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
 $data = curl_exec ($ch);
 $error = curl_error ($ch);
 curl_close ($ch);

我尝试了很多方法来实现Ajax文件:

  • 带有wget的命令行
  • curl的命令行
  • 和curl none no不使用shell_exec()

它可以工作 PHP Server的外部,但是当我单击按钮时,冻结。当我尝试下载另一个相同的冻结PHP Server上下载时,它也会冻结,即使PHP Server在执行它的外壳之外。

这不是我要下载的技术,这是一个更深层的问题。我建议使用/和/或PHP-ReportsPHP Server具有冻结下载的行为。但是我对它的可能性一无所知。

任何提示或想法都将不胜感激。

谢谢。

解决方案很简单:

我将PHP-Reports应用程序从PHP-Server移至Apache,并且已正确执行。

最新更新