public function command($cmd)
 {
     $request = new http\Client\Request("GET", $this->JobSchedulerBaseURL . ":" . $this->JobSchedulerPort . "/" . $cmd, ["User-Agent" => "My Client/0.1"]);
     $request->setOptions(["timeout" => 60]);
     $client = new http\Client();
     $client->enqueue($request)->send();
     // pop the last retrieved response
     $response = $client->getResponse();
     $this->answer = simplexml_load_string($response->getBody());
     $this->http_response_status = ["code" => $response->getResponseCode(), "info" => $response->getInfo()];
     $this->answer_error = $this->answer->answer[0]->ERROR[0];
 }
Example #2
0
 /**
  * @param string[] $headers
  * @param string $body
  * @return bool Success
  */
 public function send($headers, $body)
 {
     if (!is_array($headers)) {
         $headers = [$headers];
     }
     $body = strval($body);
     unset($headers['Host']);
     // client will generate "Host" header
     $request = new http\Client\Request('POST', $this->getEndpointUrl(), $headers, (new http\Message())->getBody()->append($body));
     $timeoutSeconds = $this->getTimeoutSeconds();
     if ($timeoutSeconds != null) {
         $request->setOptions(['timeout' => $timeoutSeconds]);
     }
     $response = (new http\Client())->enqueue($request)->send()->getResponse($request);
     $this->_lastNativeResultFromSend = $response;
     $responseHttpCode = $response->getResponseCode();
     // Any HTTP response code in the 200s is considered success
     $this->_lastSuccessFromSend = $responseHttpCode >= 200 && $responseHttpCode <= 299;
     return $this->_lastSuccessFromSend;
 }
Example #3
0
 /**
  * Creates a request.
  *
  * @param string $server Server
  * @param string $path Path
  * @param integer $method Request method
  * @param array $headers Array of headers
  * @return \http\Client\Request
  */
 protected function createRequest($server, $path, $method, array $headers = array())
 {
     $request = new \http\Client\Request($method, $server . $path);
     $request->setOptions($this->curlOptions);
     $request->setSslOptions($this->curlSslOptions);
     $request->setHeaders($headers + array('Expect' => ''));
     return $request;
 }
Example #4
0
 function posts_where($where)
 {
     // if I leave the is_search I get the normal search added (OR)
     if (is_search()) {
         $s = $_GET['s'];
         if (!empty($s)) {
             $request = new http\Client\Request("GET", "http://localhost:3058/scriptjs/query?q=" . $s, ["User-Agent" => "My Client/0.1"]);
             $request->setOptions(["timeout" => 1]);
             $client = new http\Client();
             $client->enqueue($request)->send();
             // pop the last retrieved response
             $response = $client->getResponse();
             $list = $response->getBody();
             if ($s != "empty") {
                 if ($s != "none") {
                     global $wpdb;
                     $where = str_replace('(' . $wpdb->posts . '.post_title LIKE', '(' . $wpdb->posts . '.ID in (' . $list . ')) OR (' . $wpdb->posts . '.post_title LIKE', $where);
                     $where = ' and (' . $wpdb->posts . '.ID in (' . $list . '))';
                     // SELECT SQL_CALC_FOUND_ROWS  ptbopq6_posts.ID FROM ptbopq6_posts  WHERE 1=1 (ptbopq6_posts.ID in (4365,4401))  ORDER BY ptbopq6_posts.post_title LIKE '%xapi%' DESC, ptbopq6_posts.post_date DESC LIMIT 0, 5 made by require('C:\inetpub\kneaver.com\wp-blog-header.php'), wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts
                     // made by parse-search(q) called by get_posts() all in query.php
                 }
             }
         }
     }
     return $where;
 }
Example #5
0
<?php

/*
 * 在当前目录设置 http 服务器
 * 如:php -S 0.0.0.0:3333
 */
error_reporting(E_ALL);
session_name('libo');
session_save_path('/tmp/sess');
session_start();
$_SESSION['file'] = __FILE__;
session_write_close();
$request = new http\Client\Request('GET', 'http://172.16.100.110:3333/serv.php?id=' . session_id(), ['User-Agent' => 'My Client/1.0', 'Cookie' => session_name() . '=' . session_id()]);
$request->setOptions(['connecttimeout' => 1, 'timeout' => 3]);
$client = new http\Client();
$client->enqueue($request)->send();
$response = $client->getResponse($request);
echo "[Request]\n";
print_r($request->getHeaders());
echo "\n";
print_r($request->getRequestUrl());
echo "\n";
echo "\n[Response]\n";
print_r($response->getHeaders());
echo "\n";
echo $response->getBody()->toString();