gbublik/lpdt

Long process debug tool

dev-master 2019-03-21 21:27 UTC

README

INSTALL

composer require gbublik/lpdt:dev-master

Exemple

Debug long process on backend

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

//Run nonblock socket server
$logSocketServer = GBublik\Lpdt\AsyncSocketServer::getInstance('localhost', 8082)->start();

// Useful work
$i = 0;
while (1){ 
    $logSocketServer->write('Did I create good job: ' . $i); // Send message for socket client 
    $i++;
}

//Stop socket server
$logSocketServer->stop();

CLI client

<?php
$fp = stream_socket_client("tcp://localhost:8082", $errno, $errstr, 30);
$console = fopen('php://stdout', 'w');

if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    fwrite($fp, "upgrade: Console");
    while (!feof($fp)) {
        fwrite($console, fgets($fp, 1024));
    }
    fclose($fp);
}
fclose($console);