How to run "b.php" file from "a.php" using cli command in php code and return data from "b.php" file.
-
What have you tried so far? Got any code snippets? What's stopping you from including b.php within a.php?terrorfall– terrorfall2015-09-10 11:16:56 +00:00Commented Sep 10, 2015 at 11:16
-
I don't want to include b.php file into a.php, On a.php file i have submit the form and after submit i want to trigger b.php file because b.php is a cron file.Atul– Atul2015-09-10 11:36:24 +00:00Commented Sep 10, 2015 at 11:36
-
So basically i want to run b.php file whenever a.php file form get submitted. and i want to do this by cli command in php.Atul– Atul2015-09-10 11:42:25 +00:00Commented Sep 10, 2015 at 11:42
-
@Atul have you check below code?Keval Rathi– Keval Rathi2015-09-11 06:29:52 +00:00Commented Sep 11, 2015 at 6:29
4 Answers
See the PHP documentation for exec here http://php.net/manual/en/function.exec.php
If I understand correctly you want to process data on 'a.php' and then trigger another PHP file in the form of b.php. You could probably merge these tasks to make it easier and avoid using exec all together, but below should do what you require, this is the a.php file...
//Process form data here
echo exec('php b.php');
This will return the result of b.php, you can leave the echo off if you don't require an output. It may also be worth looking into passthru as well http://php.net/manual/en/function.passthru.php
As per the documentation there are some limitations to take into consideration when it comes to PHP Safe mode
Comments
take a look at this:
by shell_exec() command you can run whatever you run in command line:
<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>
in your case:
//if form submitted
$output = shell_exec('php b.php');
Comments
Include a.php file in b.php file
and then run
D:\xampp\php>php b.php
1 Comment
Try this may be it helps you,
file_get_contents('b.php');
this code at end of your a.php file
2 Comments
shell_exec('b.php');shell_exec() will execute your b.php file in background