Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
Référence de la classe JHttpTransportSocket
+ Graphe d'héritage de JHttpTransportSocket:
+ Graphe de collaboration de JHttpTransportSocket:

Liste de tous les membres

Fonctions membres publiques

 __construct (JRegistry $options)
 request ($method, JUri $uri, $data=null, array $headers=null, $timeout=null, $userAgent=null)

Fonctions membres publiques statiques

static isSupported ()

Fonctions membres protégées

 getResponse ($content)
 connect (JUri $uri, $timeout=null)

Attributs protégés

 $connections
 $options

Description détaillée

Définition à la ligne 19 du fichier socket.php.


Documentation des constructeurs et destructeur

JHttpTransportSocket::__construct ( JRegistry  $options)

Constructor.

Paramètres:
JRegistry$optionsClient options object.
Depuis:
11.3
Exceptions:
RuntimeException

Implémente JHttpTransport.

Définition à la ligne 41 du fichier socket.php.

{
if (!self::isSupported())
{
throw new RuntimeException('Cannot use a socket transport when fsockopen() is not available.');
}
$this->options = $options;
}

Documentation des fonctions membres

JHttpTransportSocket::connect ( JUri  $uri,
  $timeout = null 
)
protected

Method to connect to a server and get the resource.

Paramètres:
JUri$uriThe URI to connect with.
integer$timeoutRead timeout in seconds.
Renvoie:
resource Socket connection resource.
Depuis:
11.3
Exceptions:
RuntimeException

Définition à la ligne 213 du fichier socket.php.

Références JUri\getHost(), JUri\getPort(), JUri\getScheme(), et JUri\isSSL().

{
$errno = null;
$err = null;
// Get the host from the uri.
$host = ($uri->isSSL()) ? 'ssl://' . $uri->getHost() : $uri->getHost();
// If the port is not explicitly set in the URI detect it.
if (!$uri->getPort())
{
$port = ($uri->getScheme() == 'https') ? 443 : 80;
}
// Use the set port.
else
{
$port = $uri->getPort();
}
// Build the connection key for resource memory caching.
$key = md5($host . $port);
// If the connection already exists, use it.
if (!empty($this->connections[$key]) && is_resource($this->connections[$key]))
{
// Connection reached EOF, cannot be used anymore
$meta = stream_get_meta_data($this->connections[$key]);
if ($meta['eof'])
{
if (!fclose($this->connections[$key]))
{
throw new RuntimeException('Cannot close connection');
}
}
// Make sure the connection has not timed out.
elseif (!$meta['timed_out'])
{
return $this->connections[$key];
}
}
if (!is_numeric($timeout))
{
$timeout = ini_get('default_socket_timeout');
}
// Capture PHP errors
$php_errormsg = '';
$track_errors = ini_get('track_errors');
ini_set('track_errors', true);
// PHP sends a warning if the uri does not exists; we silence it and throw an exception instead.
// Attempt to connect to the server
$connection = @fsockopen($host, $port, $errno, $err, $timeout);
if (!$connection)
{
if (!$php_errormsg)
{
// Error but nothing from php? Create our own
$php_errormsg = sprintf('Could not connect to resource: %s', $uri, $err, $errno);
}
// Restore error tracking to give control to the exception handler
ini_set('track_errors', $track_errors);
throw new RuntimeException($php_errormsg);
}
// Restore error tracking to what it was before.
ini_set('track_errors', $track_errors);
// Since the connection was successful let's store it in case we need to use it later.
$this->connections[$key] = $connection;
// If an explicit timeout is set, set it.
if (isset($timeout))
{
stream_set_timeout($this->connections[$key], (int) $timeout);
}
return $this->connections[$key];
}

+ Voici le graphe d'appel pour cette fonction :

JHttpTransportSocket::getResponse (   $content)
protected

Method to get a response object from a server response.

Paramètres:
string$contentThe complete server response, including headers.
Renvoie:
JHttpResponse
Depuis:
11.3
Exceptions:
UnexpectedValueException

Définition à la ligne 158 du fichier socket.php.

{
// Create the response object.
$return = new JHttpResponse;
if (empty($content))
{
throw new UnexpectedValueException('No content in response.');
}
// Split the response into headers and body.
$response = explode("\r\n\r\n", $content, 2);
// Get the response headers as an array.
$headers = explode("\r\n", $response[0]);
// Set the body for the response.
$return->body = empty($response[1]) ? '' : $response[1];
// Get the response code from the first offset of the response headers.
preg_match('/[0-9]{3}/', array_shift($headers), $matches);
$code = $matches[0];
if (is_numeric($code))
{
$return->code = (int) $code;
}
// No valid response code was detected.
else
{
throw new UnexpectedValueException('No HTTP response code found.');
}
// Add the response headers to the response object.
foreach ($headers as $header)
{
$pos = strpos($header, ':');
$return->headers[trim(substr($header, 0, $pos))] = trim(substr($header, ($pos + 1)));
}
return $return;
}
static JHttpTransportSocket::isSupported ( )
static

Method to check if http transport socket available for use

Renvoie:
boolean True if available else false
Depuis:
12.1

Implémente JHttpTransport.

Définition à la ligne 307 du fichier socket.php.

{
return function_exists('fsockopen') && is_callable('fsockopen');
}
JHttpTransportSocket::request (   $method,
JUri  $uri,
  $data = null,
array  $headers = null,
  $timeout = null,
  $userAgent = null 
)

Send a request to the server and return a JHttpResponse object with the response.

Paramètres:
string$methodThe HTTP method for sending the request.
JUri$uriThe URI to the resource to request.
mixed$dataEither an associative array or a string to be sent with the request.
array$headersAn array of request headers to send with the request.
integer$timeoutRead timeout in seconds.
string$userAgentThe optional user agent string to send with the request.
Renvoie:
JHttpResponse
Depuis:
11.3
Exceptions:
RuntimeException

Implémente JHttpTransport.

Définition à la ligne 66 du fichier socket.php.

Références JUri\getHost(), et JUri\toString().

{
$connection = $this->connect($uri, $timeout);
// Make sure the connection is alive and valid.
if (is_resource($connection))
{
// Make sure the connection has not timed out.
$meta = stream_get_meta_data($connection);
if ($meta['timed_out'])
{
throw new RuntimeException('Server connection timed out.');
}
}
else
{
throw new RuntimeException('Not connected to server.');
}
// Get the request path from the URI object.
$path = $uri->toString(array('path', 'query'));
// If we have data to send make sure our request is setup for it.
if (!empty($data))
{
// If the data is not a scalar value encode it to be sent with the request.
if (!is_scalar($data))
{
$data = http_build_query($data);
}
if (!isset($headers['Content-Type']))
{
$headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';
}
// Add the relevant headers.
$headers['Content-Length'] = strlen($data);
}
// Build the request payload.
$request = array();
$request[] = strtoupper($method) . ' ' . ((empty($path)) ? '/' : $path) . ' HTTP/1.0';
$request[] = 'Host: ' . $uri->getHost();
// If an explicit user agent is given use it.
if (isset($userAgent))
{
$headers['User-Agent'] = $userAgent;
}
// If there are custom headers to send add them to the request payload.
if (is_array($headers))
{
foreach ($headers as $k => $v)
{
$request[] = $k . ': ' . $v;
}
}
// If we have data to send add it to the request payload.
if (!empty($data))
{
$request[] = null;
$request[] = $data;
}
// Send the request to the server.
fwrite($connection, implode("\r\n", $request) . "\r\n\r\n");
// Get the response data from the server.
$content = '';
while (!feof($connection))
{
$content .= fgets($connection, 4096);
}
return $this->getResponse($content);
}

+ Voici le graphe d'appel pour cette fonction :


Documentation des données membres

JHttpTransportSocket::$connections
protected

Définition à la ligne 25 du fichier socket.php.

JHttpTransportSocket::$options
protected

Définition à la ligne 31 du fichier socket.php.


La documentation de cette classe a été générée à partir du fichier suivant :