0

我有一个PHP文件,当检查选中框并单击一个按钮时,称为JS文件,该文件具有以下代码

$.ajax ({
    type: "POST",
    url: "decisionExec.php",
    dataType: "json",
    data:({cnt:cnt,amGuide:guides.amGuide,folGuide:guides.folGuide,tichGuide:guides.tichGuide,nebGuide:guides.nebGuide,sterGuide:guides.sterGuide,ingGuide: guides.ingGuide }),
    success: function(data) {
        $("#message").html(data.message);//"Generating the files for the BookScouter results.  An email will be sent when this is completed."
        $("#start2").html(data.start);
    } // end of success

}); // end of ajax

此代码工作正常,并使用 POST 将正确的数据发送到我的 php 文件

 $amG        = $_POST['amGuide'];
 $folG       = $_POST['folGuide'];
 $tichG      = $_POST['tichGuide'];
 $nebG       = $_POST['nebGuide'];
 $sterG      = $_POST['sterGuide'];
 $ingG       = $_POST['ingGuide'];

我遇到的问题是这需要太长时间,所以我想像在其他领域一样使用 passthru 文件,但无法弄清楚如何“passthru”这些值,这是我的 passthru php 文件。

 <?php
 passthru('php /decision.php >> /web/webInv.txt &');
 $now = date("m/d/y h:i:s");
 $message = array('message' => 'An email will be sent when it is finished.',
             'start' => 'Started at approx. ' . $now);
 echo json_encode($message);
 ?>

关于我如何做到这一点的任何想法(这个文件需要大约 30 分钟来处理和发送电子邮件)

4

1 回答 1

1

我猜您是在问如何将所有 POST 参数发送到decision.php. 您可以使用serialize()or序列化它们json_encode(),并将其作为命令行参数发送到脚本。

$args = escapeshellarg(serialize($_POST));
shell_exec("php /decision.php $args >> /web/webInv.txt 2>&1 &");

使用没有意义passthru,因为输出被重定向,所以没有任何东西可以传递给客户端。

decision.php中,使用:

$_POST = unserialize($argv[1]);

获取参数。

于 2016-04-01T00:12:24.873 回答