Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.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
Php 在Raspberry Pi web服务器中从web运行python脚本_Php_Python_Webserver_Raspberry Pi - Fatal编程技术网

Php 在Raspberry Pi web服务器中从web运行python脚本

Php 在Raspberry Pi web服务器中从web运行python脚本,php,python,webserver,raspberry-pi,Php,Python,Webserver,Raspberry Pi,我有一个python脚本,它选择一个URL作为参数,并获取一些数据(通常需要30秒完成),然后用它创建一个文件。我想要的是能够从web调用脚本(我想用PHP来做,但我不介意),只获取文件路径(在脚本过程开始时打印),并让脚本在后台运行 我该怎么做?哪种方式最好 注意:我使用raspberry pi作为web服务器,python文件位于/var/www/中。php可以使用命令system()执行系统命令 要执行python脚本,可以使用以下命令: system('/path/to/python /

我有一个python脚本,它选择一个URL作为参数,并获取一些数据(通常需要30秒完成),然后用它创建一个文件。我想要的是能够从web调用脚本(我想用PHP来做,但我不介意),只获取文件路径(在脚本过程开始时打印),并让脚本在后台运行

我该怎么做?哪种方式最好


注意:我使用raspberry pi作为web服务器,python文件位于/var/www/

中。php可以使用命令
system()
执行系统命令

要执行python脚本,可以使用以下命令:

system('/path/to/python /path/to/test.py');
要使其在后台运行,请使用

system('/path/to/python /path/to/test.py &');
如果您想在后台启动脚本,但仍然获得第一行输出,我会将输出重定向到一个文件:

system('/path/to/python /path/to/test.py >/var/www/unique_file.txt &');
sleep(500); // Script has printed the file path now
$output = file_get_contents("unique_file.txt");

使用web框架,如瓶子或烧瓶。他们是非常轻和快速的发展像这样简单的东西。去这里浏览网站,你会发现你正在寻找你可以做你自己的“网络服务器”这样返回一个脚本。。。