Exemplo n.º 1
0
$problems = json_decode(file_get_contents(dirname(__FILE__) . "/problems/problems.json"), true);
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
socket_bind($sock, 0, $port) or die('Could not bind to address');
socket_listen($sock);
while (true) {
    $client = socket_accept($sock);
    $input = socket_read($client, 1024000);
    extract((array) json_decode($input));
    $file_input_title = $problems[$problem_number]["file_title"];
    $problem_timeout = $problems[$problem_number]["info"]["timeout"];
    $file_input_data = $problems[$problem_number]["info"]["input"] === "null" ? "" : file_get_contents(dirname(__FILE__) . '/problems/' . strtolower($file_input_title) . '/' . $file_input_title . '.in', FILE_USE_INCLUDE_PATH);
    $file_output_data = file_get_contents(dirname(__FILE__) . '/problems/' . strtolower($file_input_title) . '/' . $file_input_title . '.out', FILE_USE_INCLUDE_PATH);
    compileProgram("/tmp/{$processname}/{$class}.java", "/tmp/{$processname}/", "/tmp/{$processname}/{$class}.class", $class, $inputs, $args, $processname, $data, $problem_number, $file_input_title, $file_input_data, $file_output_data, $problem_timeout, $team);
    $elephant = new ElephantIOClient('http://localhost:8008', 'socket.io', 1, false, true, true);
    $elephant->init();
    $elephant->send(ElephantIOClient::TYPE_EVENT, null, null, json_encode(array('name' => 'get_subs', 'args' => $team)));
    $elephant->send(ElephantIOClient::TYPE_EVENT, null, null, json_encode(array('name' => 'recalculate', 'args' => $team)));
    $elephant->close();
    socket_close($client);
}
// Close the master sockets
socket_close($sock);
function proc_timeout($start, $problem_timeout)
{
    //check if program has timed out
    return microtime(true) - $start > $problem_timeout ? true : false;
}
function proc_exec($cmd, $inputs, $type, $problem_timeout)
{
    $output = "";
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
Exemplo n.º 2
0
<?php

require __DIR__ . '/../lib/ElephantIO/Client.php';
use ElephantIO\Client as ElephantIOClient;
$elephant = new ElephantIOClient('http://localhost:8000', 'socket.io', 1, false, true, true);
$elephant->init();
$elephant->send(ElephantIOClient::TYPE_EVENT, null, null, json_encode(array('name' => 'action', 'args' => 'foo')));
$elephant->close();
echo 'tryin to send `foo` to the event called action';