PHP code example of p / iris

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

    

p / iris example snippets



P\Iris\Message;

$request = new Message;

$request = new Message;
$request->setUserAgent('My beautiful user agent/1.0');

$request->reset();

$request->setOption(CURLOPT_NOBODY, true);
//or
$request->setOption([
    CURLOPT_NOBODY => true,
    CURLOPT_HEADER_OUT => true
]);

$request = new Message;
$request->setUserAgent('My beautiful user agent/1.0');
$request->setOption(CURLOPT_URL, 'http://www.example.com');
$request->setOption(CURLOPT_RETURNTRANSFER, true);
$request->execute();
if ($request->getErrorCode()) {
    echo $curl->getErrorCode().': '. $curl->getErrorMessage();
} else {
    $status = $request->getInfo(CURLOPTINFO_HTTP_CODE); //return the Status Code
    echo $request->getResponse();
}

$request = new Message;
$request->setUserAgent('My beautiful user agent/1.0');
$request->setOption(CURLOPT_URL, 'http://www.example.com');
$request->setOption(CURLOPT_RETURNTRANSFER, true);
$request->addListener(Message::EVENT_ON_SUCCESS, function ($res, $curl) {
    echo $curl->getInfo(CURLOPTINFO_HTTP_CODE); //return the Status Code
});
$request->addListener(Message::EVENT_ON_FAIL, function ($res, $curl) {
    echo $curl->getErrorCode().': '. $curl->getErrorMessage();
});
$request->execute();


$request = new Message;
$request->addListener(Message::EVENT_ON_SUCCESS, function ($res, $curl) {
    echo $request->getResponse();
});
$request->addListener(Message::EVENT_ON_FAIL, function ($res, $curl) {
    echo $curl->getErrorCode().': '. $curl->getErrorMessage();
});
$request->get(
    'http://www.example.com/path/to/my/script',
    ['var1' => 'value2',   ...]
);



$request = new Message;
$request->get(
    'http://www.example.com/path/to/my/script',
    json_encode(['var1' => 'value2', ...]),
    true
);
$request->execute();
echo $request->getResponse();


use P\Iris\Envelope;
use P\Iris\Batch;

$envelope = new Envelope;
$envelope->setSelectTimeout(10.00);
$evenlope->setExecTimeout(100);
$envelope->setOption(Envelope::MAXCONNECTS, 3);
$batch = new Batch($enveloppe);

$batch->addOne($request);
//or
$batch->addMany([$request1, $request2]);

$nb_messages = count($batch);

$batch->execute();