How can I run another PHP script using PHP? [duplicate] - php

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to call another PHP script from a PHP script?
I want to run all the PHP scripts in a directory using PHP. Here's what I have:
foreach(glob('*.php') as $file)
// Run $file

Look at exec. You could do something like this:
exec('/usr/bin/php ' . $file);

assuming a POSIX system
exec("nohup php $file >/dev/null 2>&1 &");

Related

How can I run php commands directly in console? [duplicate]

This question already has answers here:
How can I execute PHP code from the command line?
(6 answers)
Closed 2 years ago.
When I run PHP in my console (any cli application) and I sending a command like below, it not returned anything!
echo 'Hi!';
Is there any way to run PHP commands directly in console or just we can run a .php file?
Note: My environment variables and path is OK.
You may use PHP's interactive shell
php -a
echo 'Hi!';

PHP Run background script from cli script [duplicate]

This question already has answers here:
Running PHP script from command line as background process
(4 answers)
Closed 2 years ago.
From a php script I need to launch a new php script in background.
I expect this to be working:
shell_exec("php mySecondScript.php &");
Execution of main script hangs and secondScript is not even started. Of course if I remove '&' the script is executed, but synchronously. Any reason for this?
You don't redirect output of command.
shell_exec("php mySecondScript.php > /dev/null &");

How to redirect php exec stderr into output array when shell is csh? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to redirect stdout and stderr from csh script
I've done this many times before when the server's execution shell is sh or bash:
exec('dostuff 2>&1', $output, $return);
But now my server is on FreeBSD and the Apache execution shell is csh. I have been doing this:
exec('dostuff |& cat', $output, $return);
I am not sure this is correct, or optimal. Anybody have a better way?
Use proc_open() to get output from stderr.

call python from php [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Call Python From PHP And Get Return Code
probably a very stupid question
I have a python module lets say hi.py which have the following
print "hi"
now I want to execute this file from php
<?php
#code here
?>
So how do I call that python file from php.
Thanks
Use the exec function to invoke Python.
Example:
$output = array();
exec("python hi.py", $output);
var_dump( $output);
There are other commands for executing commands on the machine PHP is running on, see the docs.
you can call php exec function and call
python -c "print 'hi'"
or if you have larger module you can use
-m mod : run library module as a script (terminates option list)
so in the end I'd use
exec("python -m hi");
and don't forget to configure PYTHON_PATH on your server if needed
be careful doing this kind of stuff

php exec in background not working [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Call another PHP script and return control to user before the other script completes
Hello,
I'm executing this command in php:
exec('php /path/to/script.php one_argument_passed &");
But it's not executing it in the background. Is there a setting or something in php I need to do to make this work?
Maybe you have a permissions problem.

Categories