0

The idea is: Instead of launching Mercure Hub server directly in our command line like this: enter image description here

We want to make it easier by using symfony command, therefore we can launch the server like this: enter image description here

NB: We have been downloaded the archive corresponding to files that make Mercure Hub server works and where we find the executable mercure.exe and unzipped it in "mercure folder" which is in the root directory of symfony project.

Here is the Command class: enter image description here

It outputs an error: enter image description here

Even if we run it like executable: enter image description here

It also outputs an error: enter image description here

So How can we fix this and make it work in php. It seems it cannot work with absolute path.

Second Issue:

Let suppose we succeed passing the first issue and there is an alternative for that (which is not preferred one for me, so better to solve the first issue) by adding a required argument indicated the folder where mercure.exe is, like this: enter image description here

So we modify our command class: enter image description here

The output shows the following error: enter image description here

JWT_KEY not recognized whereas it works perfectly when we type the full command in command line.

So, What are the reasons of these two issues and How to fix them?

Medinho
  • 193
  • 1
  • 3
  • 10

1 Answers1

0

With Symfony 4.4 and Mercure 0.13, the code that works :

$mercure = $this->projectDir."/mercure/mercure";
$caddyFile = $this->projectDir."/mercure/Caddyfile.dev";
$command = $mercure." run -config ".$caddyFile;        
$process = new Process($command);
$process->setTimeout(null);
$process->start();
$process->wait(function ($type, $buffer) {
    if (Process::ERR === $type) {
        echo 'ERR > '.$buffer;
     } else {
         echo 'OUT > '.$buffer;
     }
});
cigien
  • 57,834
  • 11
  • 73
  • 112