PHP code example of vxsilisk / pulsarx

1. Go to this page and download the library: Download vxsilisk/pulsarx 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/ */

    

vxsilisk / pulsarx example snippets






$s = new Pulsar();
$r = $s->get('https://example.com');

$r->getStatusCode();   // 200
$r->ok();              // true
$r->getBody();         // raw body
$r->json();            // decoded JSON
$r->getElapsed();      // transfer time in seconds

$s = new Pulsar();
$s->get('https://site.com/login');            // server sets cookies
$s->post('https://site.com/cart', $payload);   // cookies sent automatically

$jar = new CookieJar();
$jar->add(new Cookie(name: 'session', value: 'abc123'));

$s->get('https://site.com', cookie: $jar);

$s = (new Pulsar())->impersonate('chrome131');
$r = $s->get('https://protected-site.com');

$s->impersonate('chrome')->get($url, headers: ['Referer: https://google.com']);

$s->impersonate('chrome131_android');   // mobile Chrome
$s->impersonate('safari172_ios');       // iOS Safari

$s = (new Pulsar())->impersonate('chrome131')->stealth();

$s->get('https://shop.com/');           // Sec-Fetch-Site: none      (direct, no Referer)
$s->get('https://shop.com/cart');       // Sec-Fetch-Site: same-origin · Referer: https://shop.com/
$s->get('https://api.shop.com/data');   // Sec-Fetch-Site: same-site · Referer: https://shop.com/cart
$s->get('https://other.com/');          // Sec-Fetch-Site: cross-site · Referer: https://api.shop.com/  (origin only)

$s = (new Pulsar())->rotate();              // realistic pool of current browsers
$s = (new Pulsar())->rotate(['chrome146', 'firefox144', 'safari260']);  // your own pool
$s = (new Pulsar())->impersonate('random'); // one random profile, fixed for the session

$s = new Pulsar();

$promises = [
    $s->getAsync('https://api.com/a', key: 'a'),
    $s->getAsync('https://api.com/b', key: 'b'),
    $s->postAsync('https://api.com/c', json: ['x' => 1], key: 'c'),
];

$responses = $s->pool($promises, concurrency: 10);  // array keyed by `key`

echo $responses['a']->getStatusCode();

$s->getAsync($url)->then(fn(Response $r) => print($r->getStatusCode()));
$s->pool($promises);

$mime = (new Mime)
    ->addPart('username', data: 'andy')
    ->addPart('avatar', filename: 'a.png', contentType: 'image/png', localPath: '/tmp/a.png')
    ->addPart('inline', filename: 'note.txt', data: 'in-memory bytes'); // no temp file needed

$s->post($url, $mime);

$mime = Mime::fromList([
    ['name' => 'username', 'data' => 'andy'],
    ['name' => 'avatar', 'filename' => 'a.png', 'local_path' => '/tmp/a.png'],
]);

$s->post($url, json: ['id' => 1, 'tags' => ['a', 'b']]);  // sets Content-Type: application/json

$s = (new Pulsar())->retries(3, baseDelay: 0.5);     // 3 tries, exponential backoff + jitter
$s->retries(5, 0.5, on: [429, 503]);                  // customise which statuses retry

$s->get('https://api.com/search', params: ['q' => 'x y', 'page' => 2]);
// -> https://api.com/search?q=x+y&page=2

$s->get($url, timeout: 5);              // override the default 60s for this call
$s->redirects(follow: true, max: 10);   // session-wide redirect policy
$r = $s->get($url);
$r->getUrl();             // final URL after redirects
$r->getRedirectCount();   // how many hops

$s->throwOnError();
try {
    $s->get('https://api.com/missing');   // 404 -> throws
} catch (PulsarException $e) { /* ... */ }

> $s = new Pulsar(verify: false);
> 

// HTTP tunnel
$s->get($url, server: ['method' => 'tunnel', 'server' => 'http://1.2.3.4:8080']);

// Authenticated proxy
$s->get($url, server: ['method' => 'custom', 'server' => 'http://1.2.3.4:8080', 'auth' => 'user:pass']);

$s = new Pulsar([
    CURLOPT_TIMEOUT        => 120,
    CURLOPT_SSL_VERIFYPEER => true,
]);