Net_Socket
[ class tree: Net_Socket ] [ index: Net_Socket ] [ all elements ]

Class: Net_Socket

Source Location: /Net_Socket-1.2.2/Net/Socket.php

Class Overview

PEAR
   |
   --Net_Socket

Generalized Socket class.


Author(s):

Copyright:

  • 1997-2017 The PHP Group

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 60]
Generalized Socket class.


[ Top ]


Class Variables

$addr =  ''

[line 84]

The IP address to connect to.
  • Access: public

Type:   string


[ Top ]

$blocking =  true

[line 72]

Whether the socket is blocking. Defaults to true.
  • Access: public

Type:   boolean


[ Top ]

$fp =  null

[line 66]

Socket file pointer.
  • Access: public

Type:   resource


[ Top ]

$lineLength =  2048

[line 104]

Number of bytes to read at a time in readLine() and readAll(). Defaults to 2048.
  • Access: public

Type:   integer


[ Top ]

$newline =  "\r\n"

[line 110]

The string to use as a newline terminator. Usually "\r\n" or "\n".
  • Access: public

Type:   string


[ Top ]

$persistent =  false

[line 78]

Whether the socket is persistent. Defaults to false.
  • Access: public

Type:   boolean


[ Top ]

$port =  0

[line 90]

The port number to connect to.
  • Access: public

Type:   integer


[ Top ]

$timeout =  null

[line 97]

Number of seconds to wait on socket operations before assuming there's no more data. Defaults to no timeout.
  • Access: public

Type:   integer|float


[ Top ]



Method Detail

connect   [line 128]

boolean|PEAR_Error connect( string $addr, [integer $port = 0], [boolean $persistent = null], [integer $timeout = null], [array $options = null])

Connect to the specified port. If called when the socket is already connected, it disconnects and connects again.
  • Return: True on success or a PEAR_Error on failure.
  • Access: public

Parameters:

string   $addr   —  IP address or host name (may be with protocol prefix).
integer   $port   —  TCP port number.
boolean   $persistent   —  (optional) Whether the connection is persistent (kept open between requests by the web server).
integer   $timeout   —  (optional) Connection socket timeout.
array   $options   —  See options for stream_context_create.

[ Top ]

disconnect   [line 225]

mixed disconnect( )

Disconnects from the peer, closes the socket.
  • Return: true on success or a PEAR_Error instance otherwise
  • Access: public

[ Top ]

enableCrypto   [line 723]

false enableCrypto( bool $enabled, integer $type)

Turns encryption on/off on a connected socket.

Parameters:

bool   $enabled   —  Set this parameter to true to enable encryption and false to disable encryption.
integer   $type   —  Type of encryption. See stream_socket_enable_crypto() for values.

[ Top ]

eof   [line 502]

bool eof( )

Tests for end-of-file on a socket descriptor.

Also returns true if the socket is disconnected.

  • Access: public

[ Top ]

gets   [line 374]

mixed gets( [int $size = null])

Get a specified line of data
  • Return: bytes of data from the socket, or a PEAR_Error if not connected. If an error occurs, FALSE is returned.
  • Access: public

Parameters:

int   $size   —  Reading ends when size - 1 bytes have been read, or a newline or an EOF (whichever comes first). If no size is specified, it will keep reading from the stream until it reaches the end of the line.

[ Top ]

getStatus   [line 353]

mixed getStatus( )

Returns information about an existing socket resource.

Currently returns four entries in the result array:

<p> timed_out (bool) - The socket timed out waiting for data
blocked (bool) - The socket was blocked
eof (bool) - Indicates EOF event
unread_bytes (int) - Number of bytes left in the socket buffer
</p>

  • Return: Array containing information about existing socket resource or a PEAR_Error instance otherwise
  • Access: public

[ Top ]

isBlocking   [line 256]

boolean isBlocking( )

Find out if the socket is in blocking mode.
  • Return: The current blocking mode.
  • Access: public

[ Top ]

read   [line 399]

string read( integer $size)

Read a specified amount of data. This is guaranteed to return, and has the added benefit of getting everything in one fread() chunk; if you know the size of the data you're getting beforehand, this is definitely the way to go.
  • Return: bytes of data from the socket, or a PEAR_Error if not connected.
  • Access: public

Parameters:

integer   $size   —  The number of bytes to read from the socket.

[ Top ]

readAll   [line 642]

string readAll( )

Read until the socket closes, or until there is no more data in

the inner PHP buffer. If the inner buffer is empty, in blocking mode we wait for at least 1 byte of data. Therefore, in blocking mode, if there is no data at all to be read, this function will never exit (unless the socket is closed on the remote end).

  • Return: All data until the socket closes, or a PEAR_Error if not connected.
  • Access: public

[ Top ]

readByte   [line 514]

integer readByte( )

Reads a byte of data
  • Return: 1 byte of data from the socket, or a PEAR_Error if not connected.
  • Access: public

[ Top ]

readInt   [line 548]

integer readInt( )

Reads an int of data
  • Return: 1 int of data from the socket, or a PEAR_Error if not connected.
  • Access: public

[ Top ]

readIPAddress   [line 588]

string readIPAddress( )

Reads an IP Address and returns it in a dot formatted string
  • Return: Dot formatted string, or a PEAR_Error if not connected.
  • Access: public

[ Top ]

readLine   [line 609]

string readLine( )

Read until either the end of the socket or a newline, whichever comes first. Strips the trailing newline from the returned data.
  • Return: All available data up to a newline, without that newline, or until the end of the socket, or a PEAR_Error if not connected.
  • Access: public

[ Top ]

readString   [line 567]

string, readString( )

Reads a zero-terminated string of data
  • Return: or a PEAR_Error if not connected.
  • Access: public

[ Top ]

readWord   [line 530]

integer readWord( )

Reads a word of data
  • Return: 1 word of data from the socket, or a PEAR_Error if not connected.
  • Access: public

[ Top ]

select   [line 670]

False select( integer $state, integer $tv_sec, [integer $tv_usec = 0])

Runs the equivalent of the select() system call on the socket with a timeout specified by tv_sec and tv_usec.
  • Return: if select fails, integer describing which of read/write/error are ready, or PEAR_Error if not connected.
  • Access: public

Parameters:

integer   $state   —  Which of read/write/error to check for.
integer   $tv_sec   —  Number of seconds for timeout.
integer   $tv_usec   —  Number of microseconds for timeout.

[ Top ]

setBlocking   [line 272]

mixed setBlocking( boolean $mode)

Sets whether the socket connection should be blocking or not. A read call to a non-blocking socket will return immediately if there is no data available, whereas it will block until there is data for blocking sockets.
  • Return: true on success or a PEAR_Error instance otherwise
  • Access: public

Parameters:

boolean   $mode   —  True for blocking sockets, false for nonblocking.

[ Top ]

setNewline   [line 243]

boolean setNewline( string $newline)

Set the newline character/sequence to use.
  • Return: True
  • Access: public

Parameters:

string   $newline   —  Newline character(s)

[ Top ]

setTimeout   [line 295]

mixed setTimeout( [integer $seconds = null], [integer $microseconds = null])

Sets the timeout value on socket descriptor, expressed in the sum of seconds and microseconds
  • Return: True on success or false on failure or a PEAR_Error instance when not connected
  • Access: public

Parameters:

integer   $seconds   —  Seconds.
integer   $microseconds   —  Microseconds, optional.

[ Top ]

setWriteBuffer   [line 324]

mixed setWriteBuffer( integer $size)

Sets the file buffering size on the stream.

See php's stream_set_write_buffer for more information.

  • Return: on success or an PEAR_Error object otherwise
  • Access: public

Parameters:

integer   $size   —  Write buffer size.

[ Top ]

write   [line 422]

mixed write( string $data, [integer $blocksize = null])

Write a specified amount of data.
  • Return: If the socket is not connected, returns an instance of PEAR_Error. If the write succeeds, returns the number of bytes written. If the write fails, returns false. If the socket times out, returns an instance of PEAR_Error.
  • Access: public

Parameters:

string   $data   —  Data to write.
integer   $blocksize   —  Amount of data to write at once. NULL means all at once.

[ Top ]

writeLine   [line 485]

mixed writeLine( string $data)

Write a line of data to the socket, followed by a trailing newline.
  • Return: result, or PEAR_Error when not connected
  • Access: public

Parameters:

string   $data   —  Data to write

[ Top ]


Documentation generated on Thu, 13 Apr 2017 17:30:02 +0000 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.