通过PHP API动态更改管理程序进程
发布时间:2020-12-13 16:00:10 所属栏目:PHP教程 来源:网络整理
导读:我设置了 Supervisor,用于管理我的工作流程. 现在,我想通过使用PHP API动态更改进程(停止某些进程并启动新进程). 我发现这个library似乎对我正在尝试的东西很有用.具体来说,我使用this更改配置,使用this管理主管. 我已设置此库并具有以下示例代码,似乎运行良
我设置了
Supervisor,用于管理我的工作流程.
现在,我想通过使用PHP API动态更改进程(停止某些进程并启动新进程). 我发现这个library似乎对我正在尝试的东西很有用.具体来说,我使用this更改配置,使用this管理主管. 我已设置此库并具有以下示例代码,似乎运行良好(从here和here) <?php require './vendor/autoload.php'; use SupervisorSupervisor; use SupervisorConnectorXmlRpc; use fXmlRpcClient; use fXmlRpcTransportHttpAdapterTransport; use IvoryHttpAdapterGuzzle5HttpAdapter; use SupervisorConfigurationConfiguration; use SupervisorConfigurationSectionSupervisord; use SupervisorConfigurationSectionProgram; use IndigoIniRenderer; //Create GuzzleHttp client $guzzleClient = new GuzzleHttpClient(['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 . "rn"; } try{ $supervisor->stopProcess('video_convert_02'); } catch(Exception $e){ echo "rn 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 "rn Config rn" . $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 SupervisorApi('127.0.0.1',9001,'user','123'); $processes = $supervisor->getAllProcessInfo(); foreach ($processes as $processInfo) { print_r($processInfo); } try { $supervisor->stopProcess('video_convert_02'); } catch (SupervisorApiException $e){ echo "rn Exception-> " . $e->getMessage(); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |