PHP code example of phergie / phergie-irc-plugin-http

1. Go to this page and download the library: Download phergie/phergie-irc-plugin-http 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/ */

    

phergie / phergie-irc-plugin-http example snippets


return [

    'plugins' => [

        // dependency
        new \Phergie\Plugin\Dns\Plugin, // Needed to do DNS lookups

        new \Phergie\Plugin\Http\Plugin([

            // All configuration is optional

            'dnsResolverEvent' => 'dns.resolver', // Event for retrieving the DNS resolver, defaults to 'dns.resolver'
            
            'guzzleClientOptions' => [], // Array with options passed into the Guzzle Client constructor (don't set a handler in here it will be overwritten)

        ]),

    ]
];

$this->emitter->emit('http.client', [
    function (GuzzleHttp\Client $client) {
        // Make HTTP requests as documented on the Guzzle docs: http://guzzle.readthedocs.org/en/latest/clients.html#asynchronous-requests
        // When making requests make sure to pass the future flag as documented: http://guzzle.readthedocs.org/en/latest/faq.html#can-guzzle-send-asynchronous-requests
    },
]);

$this->emitter->emit('http.request', [new \Phergie\Plugin\Http\Request([
    'url' => 'https://github.com/',                     // Required
    'resolveCallback' => function($response) { // Required
        // Data received do something with it
    },
    'method' => 'GET',                                  // Optional, request method
    'headers' => array(),                               // Optional, headers for the request
    'body' => '',                                       // Optional, request body to write after the headers
    'rejectCallback' => function($error) {},            // Optional, callback that gets triggered on connection errors
])]);

curl -s https://getcomposer.org/installer | php
php composer.phar install
cd tests
../vendor/bin/phpunit