0

I have this lil snippet of PHP code:

function report ($data_to_send)
{
//$exec_string = 'nohup php ../serverside/error_writer.php ' . $data_to_send . ' >/dev/null 2>&1 &';
echo "Execution string: $exec_string </p>";
exec ("../serverside/error_writer.php $data_to_send > /dev/null 2>&1 &");
}

When this function is called, the PHP program should run error_writer.php and immediately continue execution. It should not stop and wait for output.

The program is, the parameters in $exec_string never get to error_writer.php.

Here is what I know:

  • $exec_string and $data_to_send is not-empty
  • Executing error_writer.php from the command line with some made up parameters behaves as designed (the parameters are correctly parsed and the program works as-intended)
  • error_writer.php is being run, but with blank command line parameters
  • Hard coding a fixed string (such as "Hi mom!") within the PHP does NOT work
  • Looking up and googling similar problems gives no obvious indication what I am doing differently than anyone else
  • I have also tried variations of the commented-out line with similar results. Stripping out all of the "run in the background and keep going" stuff doesn't seem to help.

Does anyone have any insight as to why command line parameters are just flat-out not making it to error_writer.php? I hope what I wrote is clear enough. Thank you.

Edit 1/20: So this ended up working for me.

    $exec_string = 'php -d register_argc_argv=1 ../serverside/error_writer.php "' . $data_to_send . '" > /dev/null 2>&1 &';

-d overrides the php.ini settings, so the problem must have been in the configuration and not the actual code.

2
  • 1
    stackoverflow.com/a/10768899/2693543 ? Commented Jan 13, 2019 at 10:49
  • @Shobi I tried both of those solutions - the addslashes ($data_to_send) and the {$data_to_send} within exec (). Unfortunately the php script that is being called is still not getting any parameters. Commented Jan 13, 2019 at 12:33

0

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.