php页面在后台进程中运行另一个脚本无效

php页面在后台进程中运行另一个脚本无效,php,exec,Php,Exec,我读过这篇文章和其他一些资料 所以我有两个文件。testexec.php和testfile.php,testfile.php的目的是向表中插入一些查询。运行testexec.php的结果是成功的,但没有插入数据。我尝试直接访问testfile.php并插入数据 在testexec.php中: <?php ignore_user_abort(true); $pathFile = dirname(__FILE__) . "/textfile.php"; $cmd = "

我读过这篇文章和其他一些资料

所以我有两个文件。testexec.php和testfile.php,testfile.php的目的是向表中插入一些查询。运行testexec.php的结果是成功的,但没有插入数据。我尝试直接访问testfile.php并插入数据

在testexec.php中:

<?php
    ignore_user_abort(true);
    $pathFile = dirname(__FILE__) . "/textfile.php";
    $cmd = "usr/bin/php " . $pathFile;
    exec( $cmd , $output, $return);

    if(!$return) {
        echo "Fail";
    } else {
        echo "Success" . "<br/>";
    }
?>

在testfile.php中

<?php
    include("database.php");
    $myDB = new Database();

    $dateTime = new DateTime();
    $query = "INSERT INTO marking (description) VALUES ('Test Exec');";
    $result = $myDB->insertMysqli($query);
    if($result) {
        echo "success";
    } else {
        echo "fail";
    }
?>

尝试替换这些行

$cmd = "usr/bin/php " . $pathFile;


试着把线换掉

$cmd = "usr/bin/php " . $pathFile;


我认为这是因为您在这里使用相对路径“usr/bin/php”,尝试使用绝对路径-“/usr/bin/php”。还有一句话:一个“背景脚本”应该总是把它的活动记录在某个地方。最好在单独的日志文件中。还有一件事:如果您自己查看http服务器的错误日志文件,就很可能发现问题的原因……尝试将路径更改为“/usr/bin/php”。页面返回成功,但未插入数据。谢谢你的快速回复。我找到了问题的解决办法。只是$pathFile中的文件名错误。应为testfile而不是textfile.:日志文件真的帮助了阿卡夏。非常感谢。我认为这是因为您在这里使用相对路径“usr/bin/php”,尝试使用绝对路径-“/usr/bin/php”。还有一句话:一个“背景脚本”应该总是把它的活动记录在某个地方。最好在单独的日志文件中。还有一件事:如果您自己查看http服务器的错误日志文件,就很可能发现问题的原因……尝试将路径更改为“/usr/bin/php”。页面返回成功,但未插入数据。谢谢你的快速回复。我找到了问题的解决办法。只是$pathFile中的文件名错误。应为testfile而不是textfile.:日志文件真的帮助了阿卡夏。非常感谢。
include("database.php");
include(dirname(__FILE__) ."/database.php");