PHP Classes

File: test/php/test-timeout.php

Recommend this page to a friend!
  Classes of Nikos M.   Eazy HTTP   test/php/test-timeout.php   Download  
File: test/php/test-timeout.php
Role: Example script
Content typex: text/plain
Description: Example script
Class: Eazy HTTP
Send HTTP requests defined with a fluent interface
Author: By
Last change: v.1.2.0

* python socket implementation
* various edits, corrections
Date: 1 month ago
Size: 1,902 bytes
 

Contents

Class file image Download
<?php
// run "php -S 127.0.0.1:9000 test-server.php"

include(dirname(__FILE__) . '/../../src/php/EazyHttp.php');

function
request($do_http, $uri, $timeout)
{
    return (new
EazyHttp())
        ->
option('methods', [$do_http])
        ->
option('timeout', $timeout)
        ->
get('http://127.0.0.1:9000' . $uri)
    ;
}
function
test()
{
    try {
       
$response = request('curl', '/test/timeout.php?delay=2', 5);
       
file_put_contents(dirname(__FILE__).'/test-timeout-curl.php.txt', $response->content);
    } catch (
Exception $error) {
        echo (string)
$error;
    }

    try {
       
$response = request('file', '/test/timeout.php?delay=2', 5);
       
file_put_contents(dirname(__FILE__).'/test-timeout-file.php.txt', $response->content);
    } catch (
Exception $error) {
        echo (string)
$error;
    }

    try {
       
$response = request('socket', '/test/timeout.php?delay=2', 5);
       
file_put_contents(dirname(__FILE__).'/test-timeout-socket.php.txt', $response->content);
    } catch (
Exception $error) {
        echo (string)
$error;
    }

    try {
       
$response = request('curl', '/test/timeout.php?delay=10', 5);
       
file_put_contents(dirname(__FILE__).'/test-timeout-max-curl.php.txt', json_encode($response));
    } catch (
Exception $error) {
        echo (string)
$error;
    }

    try {
       
$response = request('file', '/test/timeout.php?delay=10', 5);
       
file_put_contents(dirname(__FILE__).'/test-timeout-max-file.php.txt', json_encode($response));
    } catch (
Exception $error) {
        echo (string)
$error;
    }

    try {
       
$response = request('socket', '/test/timeout.php?delay=10', 5);
       
file_put_contents(dirname(__FILE__).'/test-timeout-max-socket.php.txt', json_encode($response));
    } catch (
Exception $error) {
        echo (string)
$error;
    }
}

test();