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

Class: Net_Socket

Source Location: /pear/Net/Socket.php

Class Overview

PEAR
   |
   --Net_Socket

Generalized Socket class.


Author(s):

Version:

  • 1.1

Copyright:

  • 1997-2006 The PHP Group

Variables

Methods


Inherited Methods

Class: PEAR

PEAR::PEAR()
Constructor. Registers this object in $_PEAR_destructor_object_list for destructor emulation if a destructor object exists.
PEAR::delExpect()
This method deletes all occurences of the specified element from the expected error codes stack.
PEAR::expectError()
This method is used to tell which errors you expect to get.
PEAR::getStaticProperty()
If you have a class that's mostly/entirely static, and you need static
PEAR::isError()
Tell whether a value is a PEAR error.
PEAR::loadExtension()
OS independant PHP extension load. Remember to take care on the correct extension name for case sensitive OSes.
PEAR::popErrorHandling()
Pop the last error handler used
PEAR::popExpect()
This method pops one element off the expected error codes stack.
PEAR::pushErrorHandling()
Push a new error handler on top of the error handler options stack. With this you can easily override the actual error handler for some code and restore it later with popErrorHandling.
PEAR::raiseError()
This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied. If the $mode and $options parameters are not specified, the object's defaults are used.
PEAR::registerShutdownFunc()
Use this function to register a shutdown method for static classes.
PEAR::setErrorHandling()
Sets how errors generated by this object should be handled.
PEAR::staticPopErrorHandling()
PEAR::staticPushErrorHandling()
PEAR::throwError()
Simpler form of raiseError with fewer options. In most cases message, code and userinfo are enough.
PEAR::_PEAR()
Destructor (the emulated type of...). Does nothing right now, but is included for forward compatibility, so subclass destructors should always call it.

Class Details

[line 35]
Generalized Socket class.



Tags:

author:  Stig Bakken <ssb@php.net>
author:  Chuck Hagenbuch <chuck@horde.org>
version:  1.1
copyright:  1997-2006 The PHP Group


[ Top ]


Class Variables

$addr =  ''

[line 59]

The IP address to connect to.


Type:   string


[ Top ]

$blocking =  true

[line 47]

Whether the socket is blocking. Defaults to true.


Type:   boolean


[ Top ]

$fp =  null

[line 41]

Socket file pointer.


Type:   resource


[ Top ]

$lineLength =  2048

[line 79]

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


Type:   integer


[ Top ]

$persistent =  false

[line 53]

Whether the socket is persistent. Defaults to false.


Type:   boolean


[ Top ]

$port =  0

[line 65]

The port number to connect to.


Type:   integer


[ Top ]

$timeout =  false

[line 72]

Number of seconds to wait on socket connections before assuming there's no more data. Defaults to no timeout.


Type:   integer


[ Top ]



Class Methods


method connect [line 97]

boolean 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.



Tags:

return:  | PEAR_Error True on success or a PEAR_Error on failure.
access:  public


Parameters:

string   $addr   IP address or host name.
integer   $port   TCP port number.
boolean   $persistent   (optional) Whether the connection is persistent (kept open between requests by the web server).
integer   $timeout   (optional) How long to wait for data.
array   $options   See options for stream_context_create.

[ Top ]

method disconnect [line 157]

mixed disconnect( )

Disconnects from the peer, closes the socket.



Tags:

return:  true on success or an error object otherwise
access:  public


[ Top ]

method eof [line 335]

bool eof( )

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



Tags:

access:  public


[ Top ]

method gets [line 248]

$size gets( $size)

Get a specified line of data



Tags:

return:  bytes of data from the socket, or a PEAR_Error if not connected.
access:  public


Parameters:

   $size  

[ Top ]

method getStatus [line 232]

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>




Tags:

return:  Array containing information about existing socket resource or an error object otherwise
access:  public


[ Top ]

method isBlocking [line 174]

boolean isBlocking( )

Find out if the socket is in blocking mode.



Tags:

return:  The current blocking mode.
access:  public


[ Top ]

method read [line 268]

$size 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.



Tags:

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 ]

method readAll [line 468]

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).




Tags:

return:  All data until the socket closes, or a PEAR_Error if not connected.
access:  public


[ Top ]

method readByte [line 347]

1 readByte( )

Reads a byte of data



Tags:

return:  byte of data from the socket, or a PEAR_Error if not connected.
access:  public


[ Top ]

method readInt [line 380]

integer readInt( )

Reads an int of data



Tags:

return:  1 int of data from the socket, or a PEAR_Error if not connected.
access:  public


[ Top ]

method readIPAddress [line 418]

Dot readIPAddress( )

Reads an IP Address and returns it in a dot formated string



Tags:

return:  formated string, or a PEAR_Error if not connected.
access:  public


[ Top ]

method readLine [line 438]

All readLine( )

Read until either the end of the socket or a newline, whichever comes first. Strips the trailing newline from the returned data.



Tags:

return:  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 ]

method readString [line 398]

string, readString( )

Reads a zero-terminated string of data



Tags:

return:  or a PEAR_Error if not connected.
access:  public


[ Top ]

method readWord [line 363]

1 readWord( )

Reads a word of data



Tags:

return:  word of data from the socket, or a PEAR_Error if not connected.
access:  public


[ Top ]

method select [line 493]

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.



Tags:

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 ]

method setBlocking [line 189]

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.



Tags:

return:  true on success or an error object otherwise
access:  public


Parameters:

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

[ Top ]

method setTimeout [line 209]

mixed setTimeout( integer $seconds, integer $microseconds)

Sets the timeout value on socket descriptor, expressed in the sum of seconds and microseconds



Tags:

return:  true on success or an error object otherwise
access:  public


Parameters:

integer   $seconds   Seconds.
integer   $microseconds   Microseconds.

[ Top ]

method write [line 287]

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

Write a specified amount of data.



Tags:

return:  true on success or an error object otherwise
access:  public


Parameters:

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

[ Top ]

method writeLine [line 320]

mixed writeLine( $data)

Write a line of data to the socket, followed by a trailing "\r\n".



Tags:

return:  fputs result, or an error
access:  public


Parameters:

   $data  

[ Top ]


Documentation generated on Sun, 08 Jan 2012 17:52:03 +0100 by phpDocumentor 1.4.3