{"id":15374163,"url":"https://github.com/stil/curl-robot","last_synced_at":"2025-04-15T11:31:55.620Z","repository":{"id":20022879,"uuid":"23290745","full_name":"stil/curl-robot","owner":"stil","description":"Parallel URL crawling extension to curl-easy","archived":false,"fork":false,"pushed_at":"2019-11-23T06:12:46.000Z","size":21,"stargazers_count":32,"open_issues_count":1,"forks_count":10,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-23T01:02:02.299Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-24T19:39:07.000Z","updated_at":"2024-04-07T18:02:24.000Z","dependencies_parsed_at":"2022-08-24T14:09:30.413Z","dependency_job_id":null,"html_url":"https://github.com/stil/curl-robot","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stil%2Fcurl-robot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stil%2Fcurl-robot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stil%2Fcurl-robot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stil%2Fcurl-robot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stil","download_url":"https://codeload.github.com/stil/curl-robot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249061069,"owners_count":21206447,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T13:57:27.693Z","updated_at":"2025-04-15T11:31:55.376Z","avatar_url":"https://github.com/stil.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"###Installation\nYou can install this package with Composer. Run following command:\n```bash\ncomposer require stil/curl-robot:dev-master\n```\n###Example 1\n```php\n\u003c?php\nrequire __DIR__.'/../vendor/autoload.php';\n\nuse cURL\\Request;\nuse cURL\\Robot\\RobotSwarm;\nuse cURL\\Robot\\Robot;\nuse cURL\\Robot\\Event\\RequestAttachingEvent;\nuse cURL\\Robot\\Event\\RequestCompletedEvent;\nuse cURL\\Robot\\RequestProviderInterface;\n\nclass Crawler implements RequestProviderInterface\n{\n    protected $number = 0;\n\n    /**\n     * Method returning next request to execute\n     */\n    public function nextRequest()\n    {\n        return new Request(\"http://httpbin.org/delay/1?num=\".($this-\u003enumber++));\n    }\n}\n\n$swarm = new RobotSwarm();\n$swarm-\u003esetRequestProvider(new Crawler());\n$swarm-\u003egetDefaultOptions()-\u003eset([\n    CURLOPT_TIMEOUT        =\u003e 5,\n    CURLOPT_RETURNTRANSFER =\u003e true,\n    CURLOPT_HTTPHEADER     =\u003e [\n        'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0',\n        'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'\n    ]\n]);\n\n$robot1 = new Robot();\n$robot1-\u003esetQueueSize(1);\n$robot1-\u003eaddRateLimit(new RateLimit(20, 60));\n$robot1-\u003eaddListener('request.attaching', function (RequestAttachingEvent $e) {\n    echo \"Attaching request from robot1\\n\";\n});\n\n$robot2 = new Robot();\n$robot2-\u003esetQueueSize(3);\n$robot1-\u003eaddRateLimit(new RateLimit(120, 60));\n$robot2-\u003eaddListener('request.attaching', function (RequestAttachingEvent $e) {\n    // Proxy requests\n    $e-\u003erequest-\u003egetOptions()-\u003eset(CURLOPT_PROXY, '10.0.0.1:8080');\n    echo \"Attaching request from robot2 (proxied)\\n\";\n});\n\n$swarm-\u003eaddListener('request.completed', function (RequestCompletedEvent $e) {\n    $httpCode = $e-\u003eresponse-\u003egetInfo(CURLINFO_HTTP_CODE);\n\n    if ($httpCode == 200) {\n        $json = $e-\u003eresponse-\u003egetContent();\n        $data = json_decode($json, true);\n        printf(\"Successful request #%d\\n\", $data['args']['num']);\n    } else {\n        printf(\"Wrong HTTP code %d\\n\", $httpCode);\n        // Retry request until we exceeded allowed amount of attempts\n        if ($e-\u003ehandler-\u003egetAttempts() \u003c 3) {\n            printf(\"Retrying, attempt %d\\n\", $e-\u003ehandler-\u003egetAttempts());\n            $e-\u003eswarm-\u003eretry($e-\u003ehandler);\n        }\n    }\n});\n\n$swarm-\u003eadd($robot1);\n$swarm-\u003eadd($robot2);\n$swarm-\u003erun();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstil%2Fcurl-robot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstil%2Fcurl-robot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstil%2Fcurl-robot/lists"}