1

I've read this How can I run another PHP script using PHP? and some other sources.

so i have 2 files. testexec.php and testfile.php, the purpose of the testfile.php is to insert some query into table. the result running testexec.php is a success but no data inserted. i try accessing testfile.php directly and the data is inserted.

in 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/>";
    }
?>

in 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";
    }
?>
4
  • 1
    I think that's because you use relative path here "usr/bin/php" Try to use absolute - "/usr/bin/php" Commented Mar 3, 2017 at 10:30
  • Definitely. And a general remark: a "background script" always should log its activity somewhere. Preferably in a separate log file. And another thing: Most likely you would have been able to spot the cause if the issue yourself by taking a look into your http servers error log file... Commented Mar 3, 2017 at 10:34
  • try change the path to "/usr/bin/php". page return success but the data is not inserted. thanks for the quick reply. Commented Mar 3, 2017 at 10:52
  • i found solution to the problem. just wrong name file in $pathFile. should be testfile not textfile. :D the logfile really help arkascha. thanks very much. Commented Mar 3, 2017 at 11:27

1 Answer 1

0

Try to replace the lines

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

By

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

And

include("database.php");

By

include(dirname(__FILE__) ."/database.php");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.