简体   繁体   English

python 子进程popen不执行php脚本

[英]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.

相关问题 如何在 python 脚本中执行 eksctl 命令? - How to execute eksctl command in python script? 为什么 subprocess.Popen.kill() 不做任何事情? - Why isn't subprocess.Popen.kill() doing anything? 在亚马逊上启动时执行 python 脚本 Linux 2 - Execute python script at launch time on Amazon Linux 2 我们可以使用 Cloud Data Fusion 执行 python 脚本吗 - Can we execute a python script using Cloud Data Fusion 用于上传到谷歌云存储的子进程 CALL 或 python 库? - Subprocess CALL or python library for uploading to Google Cloud Storage? React 应用程序没有执行到 firebase 的请求 - React the application does not execute a request to firebase Firebase function 部分路径不执行 - Firebase function does not execute for some paths PHP 致命错误:在尝试运行 Google 的示例脚本时,vendor/google/apiclient/src/Client.php:982 中不存在文件“credentials.json” - PHP fatal error: file "credentials.json" does not exist in vendor/google/apiclient/src/Client.php:982 when trying to run Google's example script 在 GitLab 中取消作业后如何执行脚本? - How do you execute a script after a job is cancelled in GitLab? BigQuery cli bq 如何使用 EXECUTE IMMEDIATE 脚本 - BigQuery cli bq how to use EXECUTE IMMEDIATE script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM