function executeAPICommand() { $PORT = "9990"; //the port on which we are connecting to the "remote" machine $HOST = "127.0.0.1"; //the ip of the remote machine (in this case it's the same machine) if (!($sock = socket_create(AF_INET, SOCK_STREAM, 0))) { return false; } error_reporting(E_ERROR); if (!($succ = socket_connect($sock, $HOST, $PORT))) { return false; } $pakiet = array('user' => "admin", 'pass' => "tajnehaslo", 'query' => "hello"); //print_r($text); $text = json_encode($pakiet); writeSocket($sock, $text); $wynik = readSocket($sock); if (strpos($wynik, 'hi') !== false) { return true; } else { return false; } //sleep(1); }
$workload = $job->workload(); echo 'Received job: ' . $job->handle() . PHP_EOL; echo 'Workload: ' . $workload . PHP_EOL; $pipes = array(); $proc = proc_open('vendor/bin/atoum -ft -d ' . 'tests/', array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")), $pipes, __DIR__ . '/../3284862/'); stream_set_blocking($pipes[1], 0); $read = array($pipes[1]); $write = array($pipes[1]); $expect = array($pipes[1]); $status = proc_get_status($proc); while ($status['running'] === true) { $result = stream_select($read, $write, $expect, 1); if ($result) { $cnt = stream_get_contents($pipes[1]); $job->sendData($cnt); writeSocket($cnt, GEARMAN_SERVER_IP, GEARMAN_SERVER_PORT); print $cnt; } $status = proc_get_status($proc); } return $status['exitcode'] ?: 0; }); while (true) { print 'Waiting for job...' . PHP_EOL; $ret = $worker->work(); if ($worker->returnCode() != GEARMAN_SUCCESS) { print 'End of job (Status : ' . $worker->returnCode() . ')' . PHP_EOL; break; } } function getSocket($address, $port)