PHP code example of pmaxs / crawler

1. Go to this page and download the library: Download pmaxs/crawler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pmaxs / crawler example snippets



Pmaxs\Crawler\Request;
use Pmaxs\Crawler\Response;
use Pmaxs\Crawler\Crawler;

function process(Request $request, Response $response)
{
    echo $response->url." (".$response->remoteIp.":".$response->remotePort.")\n";

    echo "code: ".$response->code."; "
        ."start: ".$response->timeStart."; "
        ."finish: ".$response->timeFinish."; "
        ."time: ".($response->timeFinish - $response->timeStart)
        ."\n";

    echo $response->body."\n";
}

$Crawler = new Crawler(array(
    'time_limit'=>30,
    'rps'=>4,
));

for ($i=1; $i<=20; $i++)
    $Crawler->request(
        new Request('http://example.com/p/'.$i),
        '\process'
    );

$Crawler->process();