首页 / PHP / 通过PHP API动态更改管理程序进程
通过PHP API动态更改管理程序进程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了通过PHP API动态更改管理程序进程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2465字,纯文字阅读大概需要4分钟。
内容图文
我设置了Supervisor,用于管理我的工作流程.
现在,我想通过使用PHP API动态更改进程(停止某些进程并启动新进程).
我发现这个library似乎对我正在尝试的东西很有用.具体来说,我使用this更改配置,使用this管理主管.
我已设置此库并具有以下示例代码,似乎运行良好(从here和here)
<?php
require './vendor/autoload.php';
use Supervisor\Supervisor;
use Supervisor\Connector\XmlRpc;
use fXmlRpc\Client;
use fXmlRpc\Transport\HttpAdapterTransport;
use Ivory\HttpAdapter\Guzzle5HttpAdapter;
use Supervisor\Configuration\Configuration;
use Supervisor\Configuration\Section\Supervisord;
use Supervisor\Configuration\Section\Program;
use Indigo\Ini\Renderer;
//Create GuzzleHttp client
$guzzleClient = new \GuzzleHttp\Client(['auth' => ['user', '123']]);
// Pass the url and the guzzle client to the XmlRpc Client
$client = new Client(
'http://127.0.0.1:9001/RPC2',
new HttpAdapterTransport(new Guzzle5HttpAdapter($guzzleClient))
);
// Pass the client to the connector
// See the full list of connectors bellow
$connector = new XmlRpc($client);
$supervisor = new Supervisor($connector);
$processes = $supervisor->getAllProcesses();
foreach ($processes as $key => $processInfo) {
echo $processInfo . "\r\n";
}
try{
$supervisor->stopProcess('video_convert_02');
}
catch(Exception $e){
echo "\r\n Exception-> " . $e->getMessage();
}
$config = new Configuration;
$renderer = new Renderer;
$section = new Supervisord(['identifier' => 'supervisor']);
$config->addSection($section);
$section = new Program('test', ['command' => 'cat']);
$config->addSection($section);
echo "\r\n Config \r\n" . $renderer->render($config->toArray());
//Not sure how to use this config information to launch supervisor processes.
?>
输出如下:
pdf_convert_00
pdf_convert_01
video_convert_00
video_convert_01
video_convert_02
video_convert_03
Exception-> BAD_NAME: video_convert_02
Config
[supervisord]
identifier = supervisor
[program:test]
command = cat
我这里有两个问题:
>我不明白为什么它会抛出异常,当我试图阻止这个过程时
>如何使用配置信息启动新进程?
解决方法:
我没有使用此库,但“BAD_NAME”错误表示您的配置中没有此名称的此类进程.
顺便说一句,如果您只需要调用Supervisor API,您可以使用SupervisorXMLRPC library.这只是将您的请求转发给主管.
$supervisor = new \Supervisor\Api('127.0.0.1', 9001, 'user', '123');
$processes = $supervisor->getAllProcessInfo();
foreach ($processes as $processInfo) {
print_r($processInfo);
}
try {
$supervisor->stopProcess('video_convert_02');
}
catch (\Supervisor\ApiException $e){
echo "\r\n Exception-> " . $e->getMessage();
}
内容总结
以上是互联网集市为您收集整理的通过PHP API动态更改管理程序进程全部内容,希望文章能够帮你解决通过PHP API动态更改管理程序进程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。