Execute http requests
@param Request|Request[] $req the request object, or array of multiple requests
@return Response|Response[] result response object, or response array for multiple requests
163848
public function exec($req)
    {
        // build recs
        $recs = [];
        if ($req instanceof Request) {
            $recs[] = new Processor($this, $req);
        } elseif (is_array($req)) {
            foreach ($req as $key => $value) {
                if ($value instanceof Request) {
                    $recs[$key] = new Processor($this, $value, $key);
                }
            }
        }
        if (count($recs) === 0) {
            return false;
        }
        // loop to process
        while (true) {
            // build select fds
            $rfds = $wfds = $xrec = [];
            $xfds = null;
            foreach ($recs as $rec) {
                /* @var $rec Processor */
                self::$_processKey = $rec->key;
                if ($rec->finished || !($conn = $rec->getConn())) {
                    continue;
                }
                if ($this->_timeout !== null) {
                    $xrec[] = $rec;
                }
                $rfds[] = $conn->getSock();
                if ($conn->hasDataToWrite()) {
                    $wfds[] = $conn->getSock();
                }
            }
            self::$_processKey = null;
            if (count($rfds) === 0 && count($wfds) === 0) {
                // all tasks finished
                break;
            }
            // select sockets
            self::debug('stream_select(rfds[', count($rfds), '], wfds[', count($wfds), ']) ...');
            if ($this->_timeout === null) {
                $num = stream_select($rfds, $wfds, $xfds, null);
            } else {
                $sec = intval($this->_timeout);
                $usec = intval(($this->_timeout - $sec) * 1000000);
                $num = stream_select($rfds, $wfds, $xfds, $sec, $usec);
            }
            self::debug('select result: ', $num === false ? 'false' : $num);
            if ($num === false) {
                trigger_error('stream_select() error', E_USER_WARNING);
                break;
            } elseif ($num > 0) {
                // wfds
                foreach ($wfds as $sock) {
                    if (!($conn = Connection::findBySock($sock))) {
                        continue;
                    }
                    $rec = $conn->getExArg();
                    /* @var $rec Processor */
                    self::$_processKey = $rec->key;
                    $rec->send();
                }
                // rfds
                foreach ($rfds as $sock) {
                    if (!($conn = Connection::findBySock($sock))) {
                        continue;
                    }
                    $rec = $conn->getExArg();
                    /* @var $rec Processor */
                    self::$_processKey = $rec->key;
                    $rec->recv();
                }
            } else {
                // force to close request
                foreach ($xrec as $rec) {
                    self::$_processKey = $rec->key;
                    $rec->finish('TIMEOUT');
                }
            }
        }
        // return value
        if (!is_array($req)) {
            $ret = $recs[0]->res;
        } else {
            $ret = [];
            foreach ($recs as $key => $rec) {
                $ret[$key] = $rec->res;
            }
        }
        return $ret;
    }
1206831
public function freeRequest($req)
    {
        $req->attrs->input = null;
        unset($this->requests[$req->attrs->id]);
    }
1229419
public static function exec($url, array $req = []) {
        usleep(120000);

        // generate the POST data string
        $postData = http_build_query($req, '', '&');

        // curl handle (initialize if required)
        if (is_null(self::$ch)) {
            self::$ch = curl_init();
            curl_setopt(self::$ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt(
                self::$ch,
                CURLOPT_USERAGENT,
                'Mozilla/4.0 (compatible; CoinMarketCap PHP API; ' . php_uname('a') . '; PHP/' . phpversion() . ')'
            );
        }
        curl_setopt(self::$ch, CURLOPT_URL, $url . "?" . $postData);
        curl_setopt(self::$ch, CURLOPT_SSL_VERIFYPEER, false);

        // run the query
        $res = curl_exec(self::$ch);
        if ($res === false) {
            throw new \Exception("Curl error: " . curl_error(self::$ch));
        }

        $json = json_decode($res, true);

        // Check for the CoinMarketCap API error
        if (isset($json['error'])) {
            throw new \Exception("CoinMarketCap API error: {$json['error']}");
        }

        return $json;
    }
875287
public function executeRequest()
    {

        // curl general
        $curl_options = [
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => true,
            CURLOPT_CUSTOMREQUEST  => $this->requestType
        ];

        // set to post
        if ($this->requestType == 'POST') {
            $curl_options[CURLOPT_POST] = true;
        }

        // build url and append query params
        $url = $this->url($this->getUrl());
        $this->params[$this->oauth2->getAccessTokenName()] = $this->oauth2->getAccessToken();
        if (count($this->getParams()) > 0) {
            $url->setQuery($this->getParams());
        }
        $curl_options[CURLOPT_URL] = $url->val();

        // check request headers
        if (count($this->getHeaders()) > 0) {
            $header = [];
            foreach ($this->getHeaders() as $key => $parsed_urlvalue) {
                $header[] = "$key: $parsed_urlvalue";
            }
            $curl_options[CURLOPT_HTTPHEADER] = $header;
        }

        // init curl
        $ch = curl_init();
        curl_setopt_array($ch, $curl_options);

        // https handling
        if ($this->certificateFile != '') {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
            curl_setopt($ch, CURLOPT_CAINFO, $this->certificateFile);
        } else {
            // bypass ssl verification
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        }

        // execute the curl request
        $result = curl_exec($ch);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
        if ($curl_error = curl_error($ch)) {
            throw new OAuth2Exception($curl_error);
        } else {
            $json_decode = $this->jsonDecode($result, true);
        }
        curl_close($ch);

        return [
            'result'       => (null === $json_decode) ? $result : $json_decode,
            'code'         => $http_code,
            'content_type' => $content_type
        ];
    }
317563
protected function doRequest(RequestInterface $httpRequest)
    {
        $httpRawResponse = $httpRequest->execute();
        $httpStatusCode = $httpRequest->getInfo(CURLINFO_HTTP_CODE);
        $httpRequest->close();

        return $this->buildResponse($httpStatusCode, $httpRawResponse);
    }
335172
def execute(self, requests, resp_generator, *args, **kwargs):
        '''
            
        '''
        return [resp_generator(request) for request in requests]
773975
public function executeQuery()
    {
        try{
            $request = $this->buildRequest();
            if (is_callable($this->eventsList["BeforeExecuteQuery"])) {
                call_user_func_array($this->eventsList["BeforeExecuteQuery"], array(
                    $request,
                    $this->getCurrentAction()
                ));
            }
            $responseInfo = array();
            $response = $this->executeQueryDirect($request, $responseInfo);
            if ($responseInfo['HttpCode'] >= 400) {
                $error = $this->extractError($response);
                throw new Exception($error['Message']);
            }

            if (!empty($response)) {
                $this->processResponse($response);
            }
            $this->requestStatus = ClientRequestStatus::CompletedSuccess;
        }
        catch(Exception $e){
            $this->requestStatus = ClientRequestStatus::CompletedException;
            throw $e;
        }
    }
1213968
public function executeRequest(Request $request)
    {
        $curl = curl_init();

        if ($request->getPostBody()) {
            curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getPostBody());
        }

        $requestHeaders = $request->getRequestHeaders();
        if ($requestHeaders && is_array($requestHeaders)) {
            $curlHeaders = array();
            foreach ($requestHeaders as $k => $v) {
                $curlHeaders[] = "$k: $v";
            }
            curl_setopt($curl, CURLOPT_HTTPHEADER, $curlHeaders);
        }
        curl_setopt($curl, CURLOPT_URL, $request->getUrl());

        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getRequestMethod());
        curl_setopt($curl, CURLOPT_USERAGENT, $request->getUserAgent());

        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
        // 1 is CURL_SSLVERSION_TLSv1, which is not always defined in PHP.
        curl_setopt($curl, CURLOPT_SSLVERSION, 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, true);

        if ($request->canGzip()) {
            curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
        }

        $options = $this->client->getClassConfig('Goracash\IO\Curl', 'options');
        if (is_array($options)) {
            $this->setOptions($options);
        }

        foreach ($this->options as $key => $var) {
            curl_setopt($curl, $key, $var);
        }

        $this->client->getLogger()->debug(
            'cURL request',
            array(
                'url' => $request->getUrl(),
                'method' => $request->getRequestMethod(),
                'headers' => $requestHeaders,
                'body' => $request->getPostBody()
            )
        );

        $result = curl_exec($curl);
        if ($result === false) {
            $error = curl_error($curl);
            $code = curl_errno($curl);
            $this->client->getLogger()->error('cURL ' . $error);
            throw new Exception($error, $code);
        }

        $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
        list($responseHeaders, $responseBody) = $this->parseHttpResponse($result, $headerSize);

        $response = new Response();
        $response->code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $response->url = $request->getUrl();
        $response->method = $request->getRequestMethod();
        $response->headers = $responseHeaders;
        $response->body = $responseBody;
        $response->status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $response->setContentType(curl_getinfo($curl, CURLINFO_CONTENT_TYPE));

        $this->client->getLogger()->debug(
            'cURL response',
            array(
                'code' => $response->code,
                'headers' => $response->headers,
                'body' => $response->body,
            )
        );
        return $response;
    }
170255
public function execute(ServerRequestInterface $request, ResponseInterface $response) : ResponseInterface {
		$httpRequestResponse = new HTTPRequestResponseContainer($request, $response);

		$this->dispatchRequestFilters($httpRequestResponse);

		$this->dispatchResponseFilters($httpRequestResponse);

		return $httpRequestResponse->getResponse();
	}
1120438
public function execute(HTTPRequest $request, callable $callback, $flush = false)
    {
        try {
            return $this->callMiddleware($request, function ($request) use ($callback, $flush) {
                // Pre-request boot
                $this->getKernel()->boot($flush);
                return call_user_func($callback, $request);
            });
        } catch (HTTPResponse_Exception $ex) {
            return $ex->getResponse();
        } finally {
            $this->getKernel()->shutdown();
        }
    }
211056
public function runMiddleware(Request $req, Response $res)
    {
        $this->initMiddleware()->rewind();

        return $this->nextMiddleware($req, $res);
    }
387597
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        $model = ArrayObject::ensureArrayObject($request->getModel());

        if ($request->getToken()) {
            // Done redirection urls
            $targetUrl = $request->getToken()->getTargetUrl();
            foreach (['return_url', 'success_url', 'failure_url'] as $field) {
                if (false == $model[$field]) {
                    $model[$field] = $targetUrl;
                }
            }

            // Notify url is unique for all payment.
            // Create a dedicated controller to handle notification.
        }

        if (false == $model['date'] && ($model['return_url'] && $model['success_url'] && $model['failure_url'])) {
            $this->gateway->execute(new PaymentForm($model));
        }

        $this->gateway->execute(new Sync($model));
    }
707216
private function executeCurlRequest()
    {
        // Send the request and capture the response
        $rawResponse = $this->curl->sendRequest($this->options);

        // Fetch additional information about the request
        $responseInfo = $this->curl->getRequestInfo();

        if ( ! is_array($responseInfo))
        {
            throw new RequestException('Unable to retrieve request info array!');
        }

        // Get the error (if any)
        $errorCode = $this->curl->getErrorCode();
        $errorDescription = $this->curl->getErrorDescription();

        // Close Curl
        $this->curl->close();

        if ($errorCode > 0)
        {
            // There was a cURL error...
            throw new RequestException($errorDescription, $errorCode);
        }

        // Generate a response with the collected information
        return $this->responseFactory->make($rawResponse, $responseInfo);
    }
736231
public function handle(HTTPRequest $request)
    {
        $flush = array_key_exists('flush', $request->getVars()) || ($request->getURL() === 'dev/build');

        // Ensure boot is invoked
        return $this->execute($request, function (HTTPRequest $request) {
            return Director::singleton()->handleRequest($request);
        }, $flush);
    }
695841
public function execute(Request $request, Response $response)
    {
      // Open curl handler
      $handle = curl_init();

      // Set header callback
      curl_setopt($handle, CURLOPT_HEADERFUNCTION, array(&$response, 'header'));

      // Do not reuse connection
      curl_setopt($handle, CURLOPT_FORBID_REUSE, 1);
      curl_setopt($handle, CURLOPT_FRESH_CONNECT, 1);

      // Clear default "Expect: 100-continue" header
      //curl_setopt($handle, CURLOPT_HTTPHEADER, array('Expect:'));

      // Set custom headers
      if($request->hasHeaders())
      {
        curl_setopt($handle, CURLOPT_HEADER, 0);
        curl_setopt($handle, CURLOPT_HTTPHEADER, $request->getHeaders());
      }

      // Set authentication if needed
      if($request->hasUsername() && $request->hasPassword())
      {
        curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($handle, CURLOPT_USERPWD, $request->getUsername() . ':' . $request->getPassword());
      }

      // Set timeout
      if($request->hasTimeout())
        curl_setopt($handle, CURLOPT_TIMEOUT, $request->getTimeout());

      // Set curl options
      curl_setopt($handle, CURLOPT_URL, $request->getUrl());
      curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);

      curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
      //curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2);
      curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 0);

      curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 1);

      // Get method
      $method = $request->getMethod();

      if(!method_exists($this, strtolower($method)))
        throw new Exception(__METHOD__ . '; Request method "' .$method . '" not supported');

      // Call request method handler
      call_user_func(array($this, strtolower($method)),  $handle, $request, $response);

      // Execute curl request
      curl_exec($handle);

      // Get info
      $info = curl_getinfo($handle);

      // Set info
      $response->setInfo($info);

      // Close curl handler
      if(!is_null($handle) && is_resource($handle))
        curl_close($handle);
    }
244708
public function onInheritanceFromRequest($req)
    {
        $this->state = self::STATE_HEADERS;
        $this->addr = $req->attrs->server['REMOTE_ADDR'];
        $this->server = $req->attrs->server;
        $this->get = $req->attrs->get;
        $this->prependInput("\r\n");
        $this->onRead();
    }
717512
public function resetReturnAction($req)
    {
        $ret = wei()->userVerify->verify($req, false);
        if ($ret['code'] < 0) {
            return $this->err($ret['message']);
        }

        if (!wei()->ua->isWeChat()) {
            return wei()->response->redirect(wei()->url->full('registration/reset', $req->getQueries()));
        }

        $this->page->setTitle('重置密码');
        $userId = $req['userId'];
        $nonce = $req['nonce'];
        $timestamp = $req['timestamp'];
        $sign = $req['sign'];

        return get_defined_vars();
    }