示例#1
0
 public function addRequest(BaseRequest $request)
 {
     parent::addRequest($request);
     $oid = spl_object_hash($request);
     if (!isset($this->headers[$oid])) {
         $this->headers[$oid] = new HeaderCollector();
         $request->setOption(CURLOPT_HEADERFUNCTION, array($this->headers[$oid], "collect"));
     }
     return $this;
 }
 /**
  * @dataProvider blockingValues
  */
 public function testMutliManager($blocking)
 {
     $this->count = 0;
     $dispatcher = new EventDispatcher();
     $dispatcher->addListener(CurlEvents::MULTI_INFO, array($this, "handleMultiInfoEvent"));
     $mm = new MultiManager($dispatcher, $blocking);
     $requests = $this->makeRequestList($this->urls);
     foreach ($requests as $request) {
         $mm->addRequest($request);
     }
     $mm->execute();
     // for the "non blocking" multi manager, we need to trigger the destructor
     unset($mm);
     // verify there were events for each url
     $this->assertEquals(count($this->urls), $this->count);
     foreach ($requests as $request) {
         // if the request executed, it will have a non-zero status code
         $this->assertNotEquals(0, $request->getInfo(CURLINFO_HTTP_CODE));
     }
 }
示例#3
0
 /**
  * handle multi curl
  * @param array $stmts a list of Service instances
  * @return HttpKernel current httpkernel for method chaining
  */
 public function execute(array $stmts)
 {
     $dispatcher = new EventDispatcher();
     $dispatcher->addListener(CurlEvents::MULTI_INFO, array($this, "handleMultiInfoEvent"));
     $mm = new MultiManager($dispatcher, false);
     $this->services = array();
     foreach ($stmts as $stmt) {
         $request = $stmt->getRequest();
         $requestType = HttpKernelInterface::SUB_REQUEST;
         try {
             $event = new Event\GetResponseEvent($this, $request, $requestType);
             $this->getEventDispatcher()->dispatch(KernelEvents::REQUEST, $event);
             list($curlHandler, $contentCollector, $headerCollector) = $this->prepareRawCurlHandler($stmt, $requestType, false);
             $mm->addRequest($curlHandler);
             $this->services[] = [$stmt, [$curlHandler, $contentCollector, $headerCollector]];
         } catch (CurlErrorException $e) {
             $stmt->setError(new Exception\TransportException("CURL connection error", 1, $e));
             $event = new Event\GetResponseForExceptionEvent($this, $request, $requestType, $stmt->getError());
             $this->getEventDispatcher()->dispatch(KernelEvents::EXCEPTION, $event);
             continue;
         }
     }
     $mm->execute();
     // for the "non blocking" multi manager, we need to trigger the destructor
     unset($mm);
     return $this;
 }