简体   繁体   English

PM2 管理 PHP 脚本 - 集群模式

[英]PM2 Managing PHP Script - Cluster mode

Currently i'm successfully managing some PHP deamons (single instance) with PM2, and, so far so good!目前,我正在使用 PM2 成功管理一些 PHP 守护进程(单个实例),并且到目前为止一切顺利!

With PM2 and while managing Node.js/IO.js apps, i can launch them in cluster mode on PM2 with no stress!使用 PM2 并在管理 Node.js/IO.js 应用程序时,我可以毫无压力地在 PM2 上以集群模式启动它们! The same does not happen with the mentioned php deamons!提到的 php 守护进程不会发生同样的情况!

So, first of all, is it even possible to manage/launch clustered instances of a PHP script using PM2 (or is that PM2 feature only usable on Node.js/IO.js scripts)?那么,首先,是否可以使用 PM2 管理/启动 PHP 脚本的集群实例(或者该 PM2 功能是否仅可用于 Node.js/IO.js 脚本)?

If so (possible to do), what special "tuneups" are required to cluster the PHP scripts with PM2!?如果是这样(可能这样做),需要什么特殊的“调整”来将 PHP 脚本与 PM2 进行集群!?

While trying to launch some pm2 start xxx.php -i 2 --name XXX , i get the following error @ the error log path:在尝试启动一些pm2 start xxx.php -i 2 --name XXX ,我收到以下错误@错误日志路径:

SyntaxError: Unexpected token <
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function._load (/usr/local/lib/node_modules/pm2/node_modules/pmx/lib/transaction.js:62:21)
    at /usr/local/lib/node_modules/pm2/lib/ProcessContainer.js:200:23
    at /usr/local/lib/node_modules/pm2/node_modules/async/lib/async.js:52:16
    at /usr/local/lib/node_modules/pm2/node_modules/async/lib/async.js:1209:30
    at WriteStream.<anonymous> (/usr/local/lib/node_modules/pm2/lib/Utility.js:126:13)
    at WriteStream.EventEmitter.emit (events.js:95:17)

... that makes me believe that it can't even parse the given PHP file! ...这让我相信它甚至无法解析给定的 PHP 文件!

Thanks in advance for any help on this!在此先感谢您对此的任何帮助!

Short answer: you can't use cluster mode with php.简短回答:您不能在 php 中使用集群模式。

The pm2 cluster mode only works with javascript. pm2 集群模式仅适用于 javascript。 Internally it's using the nodejs cluster module and requiring your script ( code line ).它在内部使用 nodejs集群模块并需要您的脚本( 代码行)。 This also explains your error, pm2 tries to execute the php code with javascript (hence the SyntaxError ).这也解释了您的错误,pm2 尝试使用 javascript 执行 php 代码(因此是SyntaxError )。

When using fork mode, it's using your interpreter (here php) to launch the script.使用 fork 模式时,它使用您的解释器(此处为 php)来启动脚本。 This is why you can also run python or ruby on top of nodejs!这就是为什么你也可以在 nodejs 之上运行 python 或 ruby​​ 的原因!

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

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