EventHttpRequest::__construct

(PECL event >= 1.4.0-beta)

EventHttpRequest::__constructConstruit un objet EventHttpRequest

Description

public EventHttpRequest::__construct ( callable $callback [, mixed $data = NULL ] )

Construit un objet EventHttpRequest.

Liste de paramètres

Cette fonction ne contient aucun paramètre.

Valeurs de retour

Exemples

Exemple #1 Exemple avec EventHttpRequest::__construct()

<?php

function _request_handler($req, $base) {
	echo __FUNCTION__, PHP_EOL;

	if (is_null($req)) {
		echo "Délai d'expiration atteint\n";
	} else {
		$response_code = $req->getResponseCode();

		if ($response_code == 0) {
			echo "Connexion refusée\n";
		} elseif ($response_code != 200) {
			echo "Réponse non-attendue : $response_code\n";
		} else {
			echo "Succès : $response_code\n";
			$buf = $req->getInputBuffer();
			echo "Corps :\n";
			while ($s = $buf->readLine(EventBuffer::EOL_ANY)) {
				echo $s, PHP_EOL;
			}
		}
	}
	
	$base->exit(NULL);
}


$address = "127.0.0.1";
$port = 80;

$base = new EventBase();
$conn = new EventHttpConnection($base, NULL, $address, $port);
$conn->setTimeout(5);
$req = new EventHttpRequest("_request_handler", $base);

$req->addHeader("Host", $address, EventHttpRequest::OUTPUT_HEADER);
$req->addHeader("Content-Length", "0", EventHttpRequest::OUTPUT_HEADER);
$conn->makeRequest($req, EventHttpRequest::CMD_GET, "/index.cphp");

$base->loop();
?>

Voir aussi

LoadingChargement en cours