我正在尝试通过一个推特程序调用我的PHP进程。我使用exec()来处理这个问题:exec('python TwitterSearchProcess.py > /dev/null 2>&1 & echo $!');
我使用的脚本在终端中运行良好。但是,通过PHP进行相同的调用,它就不起作用了。我用另一个python脚本尝试了它,效果很好,但是我不知道我的两个脚本之间有什么区别。下面的脚本表示在PHP和终端中工作的脚本。在
^{pr2}$
下面的脚本是tweepy的tweepy流式处理,它只在终端中工作。在import sys
import tweepy
import os
access_token = ""
access_token_secret = ""
consumer_key = ""
consumer_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
directory = os.path.dirname(os.path.abspath(__file__))+"/"+sys.argv[1]+"/"
if not os.path.exists(directory):
os.makedirs(directory)
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, status):
print(status.text)
def on_data(self, data):
fo = open(directory+"StreamingResults.txt", "a")
fo.write(data)
def on_error(self, status_code):
print >> sys.stderr, 'Encountered error with status code:', status_code
return True # Don't kill the stream
def on_timeout(self):
print >> sys.stderr, 'Timeout...'
return True # Don't kill the stream
sapi = tweepy.streaming.Stream(auth, CustomStreamListener())
if len(sys.argv)== 3:
sapi.filter(track=[sys.argv[2]])
if len(sys.argv)== 4:
sapi.filter(track=[sys.argv[2],sys.argv[3]])
if len(sys.argv)== 5:
sapi.filter(track=[sys.argv[2],sys.argv[3],sys.argv[4]])
我检查了访问权限,并将脚本的整个文件夹设置为777。进一步说明,如果我在终端中运行流式脚本,则会收到以下警告,尽管脚本运行良好:InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
这和我的问题有关吗?在
感谢您的回复。在