0

How to run "b.php" file from "a.php" using cli command in php code and return data from "b.php" file.

4
  • What have you tried so far? Got any code snippets? What's stopping you from including b.php within a.php? Commented 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. Commented 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. Commented Sep 10, 2015 at 11:42
  • @Atul have you check below code? Commented Sep 11, 2015 at 6:29

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

0

Include a.php file in b.php file

and then run

D:\xampp\php>php b.php

1 Comment

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. 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
0

Try this may be it helps you,

file_get_contents('b.php');

this code at end of your a.php file

2 Comments

Another way use shell_exec('b.php');
shell_exec() will execute your b.php file in background

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.