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 | |
This class handles network socket through an iterator.
__construct | ( | protected string | $_host, |
int | $port, | ||
int | $timeout = 10 |
||
) |
Class constructor
string | $_host | Server host |
int | $port | Server port |
int | $timeout | Connection timeout in seconds |
__destruct | ( | ) |
Object destructor
Calls close() method
References Socket\close().
host | ( | ?string | $host = null | ) |
Get / Set host
If $host is set, set $_host and returns true. Otherwise, returns $_host value.
string | $host | Server host |
Referenced by HtmlValidator\__construct(), Akismet\callFunc(), HttpClient\doRequest(), HttpClient\getRequestURL(), HttpClient\setHost(), and Akismet\verify().
port | ( | ?int | $port = null | ) |
Get / Set port
If $port is set, set $_port and returns true. Otherwise, returns $_port value.
int | $port | Server port |
References Socket\$_port.
Referenced by HttpClient\doRequest(), HttpClient\getRequestURL(), and HttpClient\setHost().
timeout | ( | ?int | $timeout = null | ) |
Get / Set timeout
If $timeout is set, set $_timeout and returns true. Otherwise, returns $_timeout value.
int | $timeout | Connection timeout |
References Socket\$_timeout.
Referenced by HtmlValidator\__construct(), and HttpClient\setTimeout().
streamTimeout | ( | ?int | $timeout = null | ) |
Get / Set stream timeout
If $timeout is set, set $_stream_timeout and returns true. Otherwise, returns $_stream_timeout value.
null | int | $timeout | Connection timeout |
References Socket\$_stream_timeout.
setBlocking | ( | bool | $block | ) |
Set blocking
Sets blocking or non-blocking mode on the socket.
bool | $block |
References Socket\isOpen().
open | ( | ) |
Open connection.
Opens socket connection and Returns an object of type Iterator which can be iterate with a simple foreach loop.
References Socket\iterator().
Referenced by HttpClient\doRequest().
close | ( | ) |
Closes socket connection
References Socket\isOpen().
Referenced by Socket\__destruct(), and HttpClient\doRequest().
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(); ```
string|array<string> | $data Data to send |
References Socket\isOpen(), and Socket\iterator().
Referenced by HttpClient\doRequest().
flush | ( | ) |
Flush buffer
Flushes socket write buffer.
References Socket\isOpen().
|
protected |
References Socket\isOpen().
Referenced by Socket\open(), and Socket\write().
isOpen | ( | ) |
Is open
Returns true if socket connection is open.
Referenced by Socket\close(), Socket\flush(), Socket\iterator(), Socket\setBlocking(), and Socket\write().
|
protected |
Referenced by Socket\port().
|
protected |
|
protected |
Referenced by Socket\timeout().
|
protected |
|
protected |
Referenced by Socket\streamTimeout().