[英]Flask can't running in PHP
我想使用 shell_exec 命令在我的 PHP 中运行我的 Flask 应用程序 Python。 但我的 Flask 文件未运行且未显示任何内容
我在streaming.php中输入了这样的脚本:
shell_exec("python C:/XAMPP/htdocs/device_management/page/streaming/main.py");
或这个:
$command = escapeshellcmd('python C:/XAMPP/htdocs/device_management/page/streaming/main.py');
$output = shell_exec($command);
echo $output;
我的脚本 Flask "main.py"是这样的:
#!C:/Program Files/Python37-32/python.exe
import sys
import cv2
import numpy as np
from flask import Flask, request, render_template, Response, redirect, url_for
class VideoCamera(object):
def __init__(self):
self.video = cv2.VideoCapture('rtsp://username:password@"192.168.1.18":554/Streaming/Channels/102')
def __del__(self):
self.video.release()
def get_frame(self):
success, image = self.video.read()
cv2.resize(image, None, fx=1, fy=1, interpolation=cv2.INTER_AREA)
ret, jpeg = cv2.imencode('.jpg', image)
return jpeg.tobytes()
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
def gen(VideoCamera):
while True:
frame = VideoCamera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
@app.route('/camera_1')
def camera_1():
return Response(gen(VideoCamera()),
mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='127.1.0.1', port=81, debug=True)
但是,如果我像这样在 URL 目录中键入我的 Python Flask 目录:“http://localhost/device_management/page/streaming/main。
它正在运行并显示命令提示符它将显示命令提示符和我的 flask 应用程序正在运行在此处输入图像描述
如果我在下一个选项卡中输入 URL http://127.1.0.1:81 ,我可以看到闭路电视正在显示在此处输入图像描述
实际上,我可以在 PHP 中运行带有 shell_exec 的 Flask 应用程序吗?
Windows 路径需要反斜杠。 尝试:
shell_exec("python C:\\XAMPP\\htdocs\\device_management\\page\\streaming\\main.py");
还要检查权限。 如果它已经在运行,PHP 可能无法再次启动它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.