简体   繁体   English

PHP Exec()和Python脚本可扩展性

[英]PHP Exec() and Python script scaleability

I have a php application that executes Python scripts via exec() and cgi. 我有一个php应用程序,通过exec()和cgi执行Python脚本。

I have a number of pages that do this and while I know WSGI is the better way to go long-term, I'm wondering if for a small/medium amount of traffic this arrangement is acceptable. 我有很多页面可以做到这一点,虽然我知道WSGI是更好的长期方式,但我想知道如果中小量的流量这种安排是可以接受的。

I ask because a few posts mentioned that Apache has to spawn a new process for each instance of the Python interpreter which increases overhead, but I don't know how significant it is for a smaller project. 我问,因为一些帖子提到Apache必须为Python解释器的每个实例生成一个新进程,这会增加开销,但我不知道它对于一个较小的项目有多重要。

Thank you. 谢谢。

In case of CGI, server starts a copy of PHP interpreter every time it gets a request. 对于CGI,服务器每次收到请求时都会启动PHP解释器的副本。 PHP in turn starts Python process, which is killed after exec(). PHP反过来启动Python进程,在exec()之后被杀死。 There is a huge overhead on starting two processes and doing all imports on every request. 启动两个进程并在每个请求上执行所有导入都会产生巨大的开销。

In case of FastCGI or WSGI, server keeps couple processes warmed up (min and max amount of running processes is configurable), so at price of some memory you get rid of starting new process every time. 在FastCGI或WSGI的情况下,服务器保持几个进程预热(可运行进程的最小和最大数量是可配置的),因此在某些内存的价格下,您每次都无法启动新进程。 However, you still have to start/stop Python process on every exec() call. 但是,您仍然必须在每次exec()调用时启动/停止Python进程。 If you can use a Python app without exec(), eg port PHP part to Python, it would boost performance a lot. 如果你可以使用不带exec()的Python应用程序,例如将PHP部分移植到Python,它会大大提高性能。

But as you mentioned this is a small project so the only important criteria is if your current server can sustain current load. 但正如您所提到的,这是一个小项目,因此唯一重要的标准是当前服务器是否可以维持当前负载。

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

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