简体   繁体   English

PHP无法从python获得响应?

[英]PHP not getting response from python?

Php never get response If calling an API in python and it takes more than 5 minutes. PHP永远不会得到响应如果在python中调用API,则需要5分钟以上的时间。 so I was checking with time.sleep(300) in python, but it works. 所以我在用python检查time.sleep(300),但是可以用。

I do not know why php not getting response from python while calling an API. 我不知道为什么PHP在调用API时无法从python获得响应。

CODE

test.php test.php

<?php
  $file_id=1; 
  $response=exec('python /home/xyz/test.py '.$file_id);

  echo $response;

 ?>

test.py test.py

import os, json
import sys


sleep(300)
#sleep(420)
print "hello"

Maybe python is throwing an error and not printing to stdout because of that error. 也许python抛出一个错误,并且由于该错误而不打印到stdout。 Did you forget to import sleep from the time module, or where does it come from? 您是否忘记了从时间模块导入睡眠,或者它来自何处?

It should be: 它应该是:

import time
time.sleep(300)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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