[英]python subprocess popen does not execute php script
Please note, we are using aws-lambda to execute a php script using python subprocess popen function. We used the following code to call the file in python popen:请注意,我们正在使用 aws-lambda 执行 php 脚本,使用 python 子进程 popen function。我们使用以下代码调用 python popen 中的文件:
import json
import subprocess
# if the script doesn't need output.
def lambda_handler(event, context):
cmd = ["/usr/bin/php74/", "/home/admin/web/path/post.php"]
proc = subprocess.Popen(cmd, shell=True,stdout = subprocess.PIPE, stderr = subprocess.PIPE)
script_response = proc.stdout.read();
It displays a message indicating that data has been successfully logged, but it fails to execute the script.它会显示一条消息,表明数据已成功记录,但无法执行脚本。 The script is simple.
脚本很简单。 It is about inserting a row to a table.
它是关于向表中插入一行。 What shall we do?
我们该怎么办?
Update: Here is the message i'm getting on testing the lambda function:更新:这是我在测试 lambda function 时收到的消息:
Response:
null
Request ID:
"37e74321-4232-4d1f-aea8-3d5a82444de2"
Function logs:
START RequestId: 37e74321-4232-4d1f-aea8-3d5a82444de2 Version: $LATEST
END RequestId: 37e74321-4232-4d1f-aea8-3d5a82444de2
REPORT RequestId: 37e74321-4232-4d1f-aea8-3d5a82444de2 Duration: 43.42 ms Billed Duration: 44 ms Memory Size: 128 MB Max Memory Used: 53 MB Init Duration: 113.16 ms
My verified php script goes here我经过验证的 php 脚本在这里
<?php
$con1 = mysqli_connect("endpoint","###","###","database");
if(mysqli_query($con1,"insert into ex_inbox(time) values ('Done')") or die("the eror ".mysqli_error($con1)));
?>
AWS lambda environment will expire as soon as the handler method you defined returns, thus running background scripts/processes in your lambda environment directly is not possible.一旦您定义的处理程序方法返回,AWS lambda 环境就会过期,因此无法直接在您的 lambda 环境中运行后台脚本/进程。 You can work around this issue by manually waiting for some time after you call the PHP script:
您可以通过在调用 PHP 脚本后手动等待一段时间来解决此问题:
proc = subprocess.Popen(cmd, shell=True,stdout = subprocess.PIPE, stderr = subprocess.PIPE)
# wait for your subprocess to complete
time.sleep(10)
script_response = proc.stdout.read();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.