Example #1
0
 public function test_connect_create_a_redis_connection()
 {
     $client = new Client();
     $this->assertNull($client->getRedis());
     $client->connect();
     $this->assertInstanceOf('\\Redis', $client->getRedis());
 }
Example #2
0
 public function testClose()
 {
     $c = new Client();
     $c->connect();
     $this->assertInstanceOf("Bunny\\Protocol\\MethodChannelCloseOkFrame", $c->channel()->close());
     $c->disconnect();
 }
Example #3
0
 public function testRunMaxSeconds()
 {
     $client = new Client();
     $client->connect();
     $s = microtime(true);
     $client->run(1.0);
     $e = microtime(true);
     $this->assertLessThan(2.0, $e - $s);
 }
Example #4
0
 public function testClose()
 {
     $c = new Client();
     $c->connect();
     $promise = $c->channel()->close();
     $this->assertInstanceOf("React\\Promise\\PromiseInterface", $promise);
     $promise->then(function () use($c) {
         $c->stop();
     });
     $c->run();
 }
function propise_diagnostic($text, $confidence, $parameters, $myUser)
{
    global $conf;
    require_once 'Sensor.class.php';
    require_once 'Data.class.php';
    $sensor = new Sensor();
    $data = new Data();
    $sensor = $sensor->load(array('location' => $text));
    $data = $data->load(array('sensor' => $sensor->id));
    $cli = new Client();
    $cli->connect();
    $cli->talk("Diagnostique pièce : " . $text);
    $cli->talk("Humidité : " . $data->humidity . ", température : " . $data->temperature . ", Luminosité : " . $data->temperature . "%, mouvement : " . $data->mouvment . "%, bruit : " . $data->sound);
    $cli->disconnect();
}
Example #6
0
 /**
  * @medium
  */
 public function testFpmGoesAway()
 {
     // We expect this to fail with a ConnectionException
     $this->setExpectedException('\\Crunch\\FastCGI\\ConnectionException');
     // Get a MockClient instead of a real one so we can influence the connection's behaviour
     $client = new Client('localhost', 42156);
     $connection = $client->connect();
     $request = $connection->newRequest(array('Foo' => 'Bar', 'GATEWAY_INTERFACE' => 'FastCGI/1.0', 'REQUEST_METHOD' => 'POST', 'SCRIPT_FILENAME' => __DIR__ . '/Resources/scripts/sleep.php', 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'CONTENT_LENGTH' => strlen('foo=bar')), 'foo=bar');
     $connection->sendRequest($request);
     // kill fpm daemon
     exec(sprintf('kill %d', $this->pid));
     $this->pid = null;
     // Try to receive a response, it will either run indefinetly (bad!) or fail as the BE stopped
     $connection->receiveResponse($request);
 }
Example #7
0
function syncBidWinner($job)
{
    global $redis, $elephant;
    $workString = $job->workload();
    // error_log( $workString);
    $work = json_decode($workString);
    if (!isset($work->productid)) {
        return false;
    }
    $redis->set("PROD:" . $work->productid . ":BIDDER", $work->nickname);
    date_default_timezone_set('Asia/Shanghai');
    $dt = Date('Y-m-d H:i:s');
    $json = '{"FROM":"SyncBidWinner","PRODID":"' . $work->productid . '","WINNER":"' . (empty($work->nickname) ? "无" : $work->nickname) . '"}';
    error_log("[" . $dt . "] socket broadcast : " . $json);
    $socket = new Client('ws://127.0.0.1:33333');
    $socket->connect();
    $socket->send($json);
    $elephant->initialize();
    // $elephant->emit('broadcast', $json);
    $elephant->emit('broadcast', json_decode($json, true));
    $elephant->close();
}
Example #8
0
 /**
  * @return Client
  */
 public function connect()
 {
     $client = new Client();
     $client->connect($this->host, $this->port, $this->username, $this->password);
     return $client;
 }
Example #9
0
<?php

class Client
{
    private $client;
    public function __construct()
    {
        $this->client = new swoole_client(SWOOLE_SOCK_TCP);
    }
    public function connect()
    {
        if (!$this->client->connect("127.0.0.1", 9502, 1)) {
            echo "Error: {$this->client->errMsg}[{$this->client->errCode}]\n";
        }
        $msg_eof = "This is a Msg\r\n";
        $i = 0;
        while ($i < 100) {
            $this->client->send($msg_eof);
            $i++;
        }
    }
}
$client = new Client();
$client->connect();
Example #10
0
        swoole_event_add(STDIN, function ($fp) {
            $msg = trim(fgets(STDIN));
            if ($msg == 'exit') {
                $data = json_encode(array('json' => 'Chat', 'ctrl' => 'Chat', 'method' => 'offline', 'name' => $msg));
                $this->client->send($data);
                exit;
            }
            $data = json_encode(array('json' => 'Chat', 'ctrl' => 'Chat', 'method' => 'send', 'sendto' => $this->channel, 'msg' => $msg));
            $this->client->send($data);
        });
    }
    public function onClose($cli)
    {
        echo "Client close connection\n";
    }
    public function onError()
    {
        var_dump("error");
    }
    public function send($data)
    {
        $this->client->send($data);
    }
    public function isConnected()
    {
        return $this->client->isConnected();
    }
}
$cli = new Client();
$cli->connect();
Example #11
0
        echo "Get Message From Server: {$data}\n";
    }
    public function onConnect($cli)
    {
        fwrite(STDOUT, "Enter Msg:");
        swoole_event_add(STDIN, function ($fp) {
            global $cli;
            fwrite(STDOUT, "Enter Msg:");
            $msg = trim(fgets(STDIN));
            $cli->send($msg);
        });
    }
    public function onClose($cli)
    {
        echo "Client close connection\n";
    }
    public function onError()
    {
    }
    public function send($data)
    {
        $this->client->send($data);
    }
    public function isConnected()
    {
        return $this->client->isConnected();
    }
}
$cli = new Client();
$cli->connect($argv[1], $argv[2]);
Example #12
0
 public function testThatWeCanConnectToMaster()
 {
     $master = new Client('192.168.50.40', '6379', null, Client::TYPE_REDIS);
     $master->connect();
     $this->assertTrue($master->isConnected(), 'We can connect to the master node');
 }
//
// Retour si déjà connecté...
//
if ($_COMPTE) {
    $Navig->redirect("compte.php");
}
//////////////////////////////////////////////////
//
// Tester email+password...
//
if (isset($_POST['deja_compte'])) {
    $DEMANDE_CONNEXION = true;
    $compte_email = trim($_POST['compte_email']);
    $compte_passwd = trim($_POST['compte_passwd']);
    $Client = new Client();
    if ($_COMPTE = $Client->connect($compte_email, $compte_passwd)) {
        $Caddie->client($_COMPTE);
        // mettre à jour le caddie avec les anciennes et les nouvelles lignes...
        $Navig->redirect($Navig->page_demande_connect_compte);
        // pour recharger la page qui a demandé la connexion...
    } else {
        $ERR = trad($Client->err_num);
    }
    # Ancre...
    $ancre = "connexion";
}
//////////////////////////////////////////////////
//
// OUBLI MOT DE PASSE...
//
if (isset($_POST['oubli_passwd_email'])) {
Example #14
0
function common_listen($command, $text, $confidence, $user)
{
    echo "\n" . 'diction de la commande : ' . $command;
    $response = array();
    Plugin::callHook("vocal_command", array(&$response, YANA_URL . '/action.php'));
    $commands = array();
    echo "\n" . 'Test de comparaison avec ' . count($response['commands']) . ' commandes';
    foreach ($response['commands'] as $cmd) {
        if ($command != $cmd['command']) {
            continue;
        }
        if (!isset($cmd['parameters'])) {
            $cmd['parameters'] = array();
        }
        if (isset($cmd['callback'])) {
            //Catch des commandes pour les plugins en format client v2
            echo "\n" . 'Commande trouvée, execution de la fonction plugin ' . $cmd['callback'];
            call_user_func($cmd['callback'], $text, $confidence, $cmd['parameters'], $user);
        } else {
            //Catch des commandes pour les plugins en format  client v1
            echo "\n" . 'Commande ancien format trouvée, execution de l\'url ' . $cmd['url'] . '&token=' . $user->getToken();
            $result = file_get_contents($cmd['url'] . '&token=' . $user->getToken());
            $result = json_decode($result, true);
            if (is_array($result)) {
                $client = new Client();
                $client->connect();
                foreach ($result['responses'] as $resp) {
                    switch ($resp['type']) {
                        case 'talk':
                            $client->talk($resp['sentence']);
                            break;
                        case 'sound':
                            $client->sound($resp['file']);
                            break;
                        case 'command':
                            $client->execute($resp['program']);
                            break;
                    }
                }
                $client->disconnect();
            }
        }
    }
}
Example #15
0
function vocalinfo_give_me_all($text, $confidence, $parameters)
{
    $cli = new Client();
    $cli->connect();
    $cli->talk("Je peux parler, evidemment, et t\\'écouter plus précisément qu\\'avant");
    $cli->talk("Je peux eprouver et montrer des sentiments");
    $cli->talk("Comme la colère");
    $cli->emotion("angry");
    $cli->talk("Ou la timidité");
    $cli->emotion("shy");
    $cli->talk("Et tout un tas d\\'autres lubies humaines");
    $cli->talk("Je peux aussi exécuter un programme");
    $cli->execute("D:\\Programme_installes\\Qt\\Tools\\QtCreator\\bin\\qtcreator.exe");
    $cli->talk("ou un son");
    $cli->sound("C:/poule.wav");
    $cli->talk("ou te montrer des images");
    $cli->image("yana.jpg");
    $cli->talk("ou executer une commande domotique");
    //system('gpio write 1 1');
    //$cli->talk("ou executer un humain");
    //$cli->talk("non je déconne.");
    $cli->disconnect();
}
Example #16
0
<?php

namespace Bunny;

require_once __DIR__ . "/../vendor/autoload.php";
$c = new Client();
$ch = $c->connect()->channel();
$ch->queueDeclare("bench_queue");
$ch->exchangeDeclare("bench_exchange");
$ch->queueBind("bench_queue", "bench_exchange");
$t = null;
$count = 0;
$ch->run(function (Message $msg, Channel $ch, Client $c) use(&$t, &$count) {
    if ($t === null) {
        $t = microtime(true);
    }
    if ($msg->content === "quit") {
        printf("Pid: %s, Count: %s, Time: %.4f\n", getmypid(), $count, microtime(true) - $t);
        $c->stop();
    } else {
        ++$count;
    }
}, "bench_queue", "", false, true);
$c->disconnect();
 public function testClientConnect()
 {
     self::$client = new Client();
     $this->assertTrue(self::$client->connect(), 'Клиент не может соединиться');
 }
Example #18
0
    }
    public function onReceive($cli, $data)
    {
        echo "Get Message From Server: {$data}\n";
    }
    public function onConnect($cli)
    {
        $cli->send("hello world\n");
    }
    public function onClose($cli)
    {
        echo "Client close connection\n";
    }
    public function onError($cli)
    {
        echo "connect fail\n";
    }
    public function send($data)
    {
        $this->client->send($data);
    }
    public function isConnected()
    {
        return $this->client->isConnected();
    }
}
require __DIR__ . '/../library/Common.php';
$client_config = (include 'config.php');
$cli = new Client();
$cli->connect($client_config);
Example #19
0
<?php

/**
 * Created by PhpStorm.
 * User: bensoer
 * Date: 01/10/15
 * Time: 2:00 PM
 */
require_once './Client.php';
$clientService = new Client("SEND");
$clientService->connect();
$clientService->executeRequest("./data/testData.txt");
Example #20
0
<?php

namespace Bunny;

require_once __DIR__ . "/../vendor/autoload.php";
$c = new Client();
$c->connect();
$ch = $c->channel();
$ch->queueDeclare("bench_queue");
$ch->exchangeDeclare("bench_exchange");
$ch->queueBind("bench_queue", "bench_exchange");
$body = <<<EOT
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyza
EOT;
$time = microtime(true);
$max = isset($argv[1]) ? (int) $argv[1] : 1;
for ($i = 0; $i < $max; $i++) {
    $ch->publish($body, [], "bench_exchange");
}
echo microtime(true) - $time, "\n";
$ch->publish("quit", [], "bench_exchange");
$c->disconnect();
    {
        if (!$this->client->connect("127.0.0.1", 9501, 1)) {
            echo "Error: connect error";
            return;
        }
    }
    public function onReceive($client, $data)
    {
        echo "Get Message From Server:{$data}\n";
    }
    public function onConnect($client)
    {
        fwrite(STDOUT, "Enter Msg:");
        swoole_event_add(STDIN, function ($fp) {
            global $client;
            fwrite(STDOUT, "Enter Msg:");
            $msg = trim(fgets(STDIN));
            $client->send($msg);
        });
    }
    public function onClose($client)
    {
        echo "the {$client} is closed";
    }
    public function onError($client)
    {
    }
}
$redis_cli = new Client();
$redis_cli->connect();