Source for file socket.php
Documentation is available at socket.php
* base include file for SimpleTest
* @subpackage MockObjects
* @version $Id: socket.php 1723 2008-04-08 00:34:10Z lastcraft $
* include SimpleTest files
require_once(dirname(__FILE__
) .
'/compatibility.php');
* Stashes an error for later. Useful for constructors
* until PHP gets exceptions.
var $_error =
'Constructor not chained';
* Sets the error to empty.
* Test for an outstanding error.
* @return boolean True if there is an error.
* Accessor for an outstanding error.
* @return string Empty string if no error otherwise
* Sets the internal error.
* @param string Error message to stash.
* Resets the error state to no error.
* Wrapper for TCP/IP socket.
* Opens a socket for reading and writing.
* @param string $host Hostname to send request to.
* @param integer $port Port on remote machine to open.
* @param integer $timeout Connection timeout in seconds.
* @param integer $block_size Size of chunk to read.
function SimpleSocket($host, $port, $timeout, $block_size =
255) {
if (! ($this->_handle =
$this->_openSocket($host, $port, $error_number, $error, $timeout))) {
$this->_setError("Cannot open [$host:$port] with [$error] within [$timeout] seconds");
$this->_block_size =
$block_size;
* Writes some data to the socket and saves alocal copy.
* @param string $message String to send to socket.
* @return boolean True if successful.
function write($message) {
$this->_sent .=
$message;
* Reads data from the socket. The error suppresion
* is a workaround for PHP4 always throwing a warning
* @return integer/boolean Incoming bytes. False
* Accessor for socket open state.
* @return boolean True if open.
* Closes the socket preventing further reads.
* Cannot be reopened once closed.
* @return boolean True if successful.
* Accessor for content so far.
* @return string Bytes sent only.
* Actually opens the low level socket.
* @param string $host Host to connect to.
* @param integer $port Port on host.
* @param integer $error_number Recipient of error code.
* @param string $error Recipoent of error message.
* @param integer $timeout Maximum time to wait for connection.
function _openSocket($host, $port, &$error_number, &$error, $timeout) {
return @fsockopen($host, $port, $error_number, $error, $timeout);
* Wrapper for TCP/IP socket over TLS.
* Opens a secure socket for reading and writing.
* @param string $host Hostname to send request to.
* @param integer $port Port on remote machine to open.
* @param integer $timeout Connection timeout in seconds.
* Actually opens the low level socket.
* @param string $host Host to connect to.
* @param integer $port Port on host.
* @param integer $error_number Recipient of error code.
* @param string $error Recipient of error message.
* @param integer $timeout Maximum time to wait for connection.
function _openSocket($host, $port, &$error_number, &$error, $timeout) {
return parent::_openSocket("tls://$host", $port, $error_number, $error, $timeout);
Documentation generated on Sun, 04 May 2008 09:22:10 -0500 by phpDocumentor 1.3.0