简体   繁体   中英

How to run “b.php” file from “a.php” using cli command in php code

如何在PHP代码中使用cli命令从“ a.php”运行“ b.php”文件,并从“ b.php”文件返回数据。

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

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');

Include a.php file in b.php file

and then run

D:\\xampp\\php>php b.php

Try this may be it helps you,

file_get_contents('b.php');

this code at end of your a.php file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM