简体   繁体   English

使用composer为Supervisor安装PHP库

[英]Installing PHP library for Supervisor using composer

I want to use Supervisor to manager my processes. 我想使用Supervisor来管理我的流程。 I have got it installed on my Amazon linux Machine and the basic setup runs fine as per the config file. 我已经将其安装在我的Amazon linux机器上,并且基本配置按配置文件运行正常。

Now, I want to change the processes dynamically. 现在,我想动态地更改流程。 Since it needs the config file to be changed every time and a restart, using PHP library to do the same seems to be a good option. 由于它需要每次更改配置文件并重新启动,因此使用PHP库执行相同的操作似乎是一个不错的选择。

Specifically I am going through SupervisorPHP config to change the configuration dynamically and SupervisorPHP to manager Supervisor through PHP. 具体来说,我正在参加SupervisorPHP配置动态和更改配置SupervisorPHP通过PHP来的经理主管。

Following the README for SupervisorPHP config , I got it installed via composer 按照README for SupervisorPHP的配置 ,我通过composer安装了它。

composer require supervisorphp/configuration

I copied the sample code 我复制了示例代码

<?php
    use Supervisor\Configuration\Configuration;
    use Supervisor\Configuration\Section\Supervisord;
    use Supervisor\Configuration\Section\Program;
    use Indigophp\Ini\Rendere;

    $config = new Configuration;
    $renderer = new Renderer;

    $section = new Supervisord(['identifier' => 'supervisor']);
    $config->addSection($section);

    $section = new Program('test', ['command' => 'cat']);
    $config->addSection($section);

    echo $renderer->render($config->toArray());

When I run this code, I get the following error: 运行此代码时,出现以下错误:

PHP Fatal error:  Class 'Supervisor\Configuration\Configuration' not found in test.php on line 7

I also tried to clone the repo and include the files individually, however it shows error for other dependencies. 我还尝试克隆存储库并单独包含文件,但是对于其他依赖项却显示错误。 It would be great if I could use this. 如果我可以使用它,那就太好了。

There are 2 mistakes in the above code. 上面的代码中有2个错误。

The first mistake is that you do not use the autoloader provided by composer so that php can find the necessary classes. 第一个错误是您没有使用composer提供的自动加载器,因此php可以找到必要的类。 To do so just add require __DIR__ . '/vendor/autoload.php'; 为此,只需添加require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php'; (If the vendor folder is in a different path relative to the sample script then adjust accordingly). (如果供应商文件夹相对于示例脚本位于不同的路径,则进行相应调整)。

The second mistake is in the use statement for Indigophp. 第二个错误是在Indigophp的use语句中。 Apart from the obvious typo in the word Renderer, if you check the source of Indigo you will see that it must be use Indigo\\Ini\\Renderer; 除了Renderer一词中明显的错别字外,如果检查Indigo的来源,您会发现它必须use Indigo\\Ini\\Renderer;

So the correct code to test your installation is: 因此,测试安装的正确代码是:

<?php
require __DIR__ . '/vendor/autoload.php';

use Supervisor\Configuration\Configuration;
use Supervisor\Configuration\Section\Supervisord;
use Supervisor\Configuration\Section\Program;
use Indigo\Ini\Renderer;

$config = new Configuration;
$renderer = new Renderer;

$section = new Supervisord(['identifier' => 'supervisor']);
$config->addSection($section);

$section = new Program('test', ['command' => 'cat']);
$config->addSection($section);

echo $renderer->render($config->toArray());

Running the above code, you should get the following output: 运行上面的代码,您应该获得以下输出:

[supervisord]
identifier = supervisor

[program:test]
command = cat

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

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