Zend\Log\Writer\Stream is interfering shell input

100 views Asked by At

I'm using Zend Framework's logger to log events.

$logger = new \Zend\Log\Logger();
$writer = new Zend\Log\Writer\Stream("/path/to/debug.log");
$logger->addWriter($writer);

and log it with:

$logger->notice('Testing');

Then I run the PHP in shell (as a background process) by:

(php /path/to/test.php &) 

or

php /path/to/test.php & disown

or

setsid php '/path/to/test.php'

But after the process is running in background, whenever it writes logs, the carriage (the blinking input dot) moves to other line in shell, interfering my input. How can I make the logger stop interfering the shell input?

The full codes are as follow:

require_once("vendor/autoload.php");
use Devristo\Phpws\Server\WebSocketServer;
$loop = \React\EventLoop\Factory::create();

// Create a logger
$logger = new \Zend\Log\Logger();
$writer = new Zend\Log\Writer\Stream("/path/to/debug.log");
$logger->addWriter($writer);

// Create WebSocket server
$server = new WebSocketServer("tcp://0.0.0.0:12345", $loop, $logger);
$loop->addPeriodicTimer(1.0, function() use($server, $logger){
    $string = get_information();
    //$logger->notice("Broadcasting to all clients: $string");
    if($string !== null) {
        foreach($server->getConnections() as $client) {
            $client->sendString($string);
        }
    }
});

// Bind the server
$server->bind();

// Start the event loop
$loop->run();

p.s. get_information() just returns a simple string.

0

There are 0 answers