Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用exec()调用php函数_Php_Exec - Fatal编程技术网

使用exec()调用php函数

使用exec()调用php函数,php,exec,Php,Exec,我试图使用exec()运行参数,并将参数传递给array_module.php中名为new_array()的php函数,并期望返回数组,但运气不佳。使用以下格式: $cmd = exec('cd "c:/wamp/www/test_array" && php array_module.php "'.$input['first'].'" "'.$input['second'].'" '); 感谢您的帮助不要通过命令行调用其他文件导入另一个文件,使其功能可用,只需直接调

我试图使用exec()运行参数,并将参数传递给array_module.php中名为new_array()的php函数,并期望返回数组,但运气不佳。使用以下格式:

$cmd = exec('cd "c:/wamp/www/test_array" && php array_module.php "'.$input['first'].'" 
     "'.$input['second'].'" ');

感谢您的帮助

不要通过命令行调用其他文件导入另一个文件,使其功能可用,只需直接调用该功能:

require_once 'c:/wamp/www/test_array/array_module.php';

$result = new_array($input['first'], $input['second']);
这假设
array\u module.php
是以一种合理的方式编写的,因此它当然可以在其他地方导入,例如:

<?php

function new_array($one, $two) {
    ...
    return $result;
}

为什么
exec
?!为什么不
require_once'array_module.php'$结果=someFunc($input)
像一个理智的人吗?对在Click中使用php的新手表示歉意,您能详细说明一下吗?我可以用什么包装require_once'array_module.php'$结果=someFunc($input);不幸的是,我们必须在后台运行这个函数,这是什么意思,“后台”?为什么?它将与另一个函数并行运行,因为使用CLI
exec调用的cron作业从一开始就不会“并行”运行任何东西。关于如何使用PHP并行运行有很多问题,请先看看这些问题。