Dotclear  2.29
 All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Socket Class Reference
Inheritance diagram for Socket:
[legend]

Public Member Functions

 __construct (protected string $_host, int $port, int $timeout=10)
 
 __destruct ()
 
 host (?string $host=null)
 
 port (?int $port=null)
 
 timeout (?int $timeout=null)
 
 streamTimeout (?int $timeout=null)
 
 setBlocking (bool $block)
 
 open ()
 
 close ()
 
 write ($data)
 
 flush ()
 
 isOpen ()
 

Protected Member Functions

 iterator ()
 

Protected Attributes

 $_port
 
 $_transport = ''
 
 $_timeout
 
 $_handle
 
 $_stream_timeout
 

Detailed Description

This class handles network socket through an iterator.

Constructor & Destructor Documentation

__construct ( protected string  $_host,
int  $port,
int  $timeout = 10 
)

Class constructor

Parameters
string$_hostServer host
int$portServer port
int$timeoutConnection timeout in seconds
__destruct ( )

Object destructor

Calls close() method

References Socket\close().

Here is the call graph for this function:

Member Function Documentation

host ( ?string  $host = null)

Get / Set host

If $host is set, set $_host and returns true. Otherwise, returns $_host value.

Parameters
string$hostServer host
Returns
string|true

Referenced by HtmlValidator\__construct(), Akismet\callFunc(), HttpClient\doRequest(), HttpClient\getRequestURL(), HttpClient\setHost(), and Akismet\verify().

Here is the caller graph for this function:

port ( ?int  $port = null)

Get / Set port

If $port is set, set $_port and returns true. Otherwise, returns $_port value.

Parameters
int$portServer port
Returns
int|true

References Socket\$_port.

Referenced by HttpClient\doRequest(), HttpClient\getRequestURL(), and HttpClient\setHost().

Here is the caller graph for this function:

timeout ( ?int  $timeout = null)

Get / Set timeout

If $timeout is set, set $_timeout and returns true. Otherwise, returns $_timeout value.

Parameters
int$timeoutConnection timeout
Returns
int|true

References Socket\$_timeout.

Referenced by HtmlValidator\__construct(), and HttpClient\setTimeout().

Here is the caller graph for this function:

streamTimeout ( ?int  $timeout = null)

Get / Set stream timeout

If $timeout is set, set $_stream_timeout and returns true. Otherwise, returns $_stream_timeout value.

Parameters
null | int$timeoutConnection timeout
Returns
null|int|true

References Socket\$_stream_timeout.

setBlocking ( bool  $block)

Set blocking

Sets blocking or non-blocking mode on the socket.

Parameters
bool$block
Returns
bool

References Socket\isOpen().

Here is the call graph for this function:

open ( )

Open connection.

Opens socket connection and Returns an object of type Iterator which can be iterate with a simple foreach loop.

Returns
Iterator|false

References Socket\iterator().

Referenced by HttpClient\doRequest().

Here is the call graph for this function:

Here is the caller graph for this function:

close ( )

Closes socket connection

References Socket\isOpen().

Referenced by Socket\__destruct(), and HttpClient\doRequest().

Here is the call graph for this function:

Here is the caller graph for this function:

write (   $data)

Send data

Sends data to current socket and returns an object of type Iterator which can be iterate with a simple foreach loop.

$data can be a string or an array of lines.

Example:

```php $s = new Socket('www.google.com',80,2); $s->open(); $data = [ 'GET / HTTP/1.0' ]; foreach($s->write($data) as $v) { echo $v."\n"; } $s->close(); ```

Parameters
string|array<string>$data Data to send
Returns
Iterator|false

References Socket\isOpen(), and Socket\iterator().

Referenced by HttpClient\doRequest().

Here is the call graph for this function:

Here is the caller graph for this function:

flush ( )

Flush buffer

Flushes socket write buffer.

Returns
void|false

References Socket\isOpen().

Here is the call graph for this function:

iterator ( )
protected

Iterator

Returns
Iterator|false

References Socket\isOpen().

Referenced by Socket\open(), and Socket\write().

Here is the call graph for this function:

Here is the caller graph for this function:

isOpen ( )

Is open

Returns true if socket connection is open.

Returns
bool

Referenced by Socket\close(), Socket\flush(), Socket\iterator(), Socket\setBlocking(), and Socket\write().

Here is the caller graph for this function:

Field Documentation

$_port
protected

Referenced by Socket\port().

$_transport = ''
protected
$_timeout
protected

Referenced by Socket\timeout().

$_handle
protected
$_stream_timeout
protected

Referenced by Socket\streamTimeout().


The documentation for this class was generated from the following file: