RollingCurl\RollingCurl::setCallback PHP Method

setCallback() public method

It can be an anonymous function: $rc = new RollingCurl(); $rc->setCallback(function($request, $rolling_curl) { process }); Or an existing function: class MyClass { function doCurl() { $rc = new RollingCurl(); $rc->setCallback(array($this, 'callback')); } Cannot be private or protected public function callback($request, $rolling_curl) { process } } The called code should expect two parameters: \RollingCurl\Request $request, \RollingCurl\RollingCurl $rollingCurl $request is original request object, but now with body, headers, response code, etc $rollingCurl is the rolling curl object itself (useful if you want to re/queue a URL)
public setCallback ( callable $callback ) : RollingCurl
$callback callable
return RollingCurl
    public function setCallback($callback)
    {
        if (!is_callable($callback)) {
            throw new \InvalidArgumentException("must pass in a callable instance");
        }
        $this->callback = $callback;
        return $this;
    }

Usage Example

Ejemplo n.º 1
0
 public function performAction()
 {
     $rollingCurl = new RollingCurl();
     foreach ($this->getPerlTablesUrlList() as $url) {
         $rollingCurl->get($url);
     }
     $rollingCurl->setCallback(function (Request $request, RollingCurl $rollingCurl) {
         $this->response->addContent($request->getUrl());
         $content = $request->getResponseText();
         $this->parsePerlTable($content);
     })->execute();
 }
All Usage Examples Of RollingCurl\RollingCurl::setCallback