CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 1.2 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.2
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbAclSchema
  • DbConfigTask
  • DboAdodb
  • DboDb2
  • DboFirebird
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOdbc
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • DboSybase
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • Flay
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • i18nSchema
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JsHelper
  • JsHelperObject
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginTask
  • ProjectTask
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • SessionsSchema
  • Set
  • Shell
  • String
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • __enclose
  • make_clean_css
  • mb_encode_mimeheader
  • mb_stripos
  • mb_stristr
  • mb_strlen
  • mb_strpos
  • mb_strrchr
  • mb_strrichr
  • mb_strripos
  • mb_strrpos
  • mb_strstr
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count
  • write_css_cache

Class HttpSocket

Cake network socket connection class.

Core base class for HTTP network communication.

Object
Extended by CakeSocket
Extended by HttpSocket
Package: cake\cake\libs
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: The MIT License
Location: http_socket.php

Properties summary

  • $config public
    array
    Default configuration settings for the HttpSocket
  • $description public
    string
    Object description
  • $lineBreak public
    string
    String that represents a line break.
  • $quirksMode public
    boolean

    When one activates the $quirksMode by setting it to true, all checks meant to enforce RFC 2616 (HTTP/1.1 specs) will be disabled and additional measures to deal with non-standard responses will be enabled.

  • $request public
    array
    The default values to use for a request
  • $response public
    array
    The default structure for storing the response

Inherited Properties

  • _baseConfig, connected, connection, lastError _log

Method Summary

  • __construct() public
    Build an HTTP Socket using the specified configuration.
  • __tokenEscapeChars() public
    Gets escape chars according to RFC 2616 (HTTP 1.1 specs).
  • buildCookies() public
    undocumented function
  • buildHeader() public
    Builds the header.
  • buildRequestLine() public
    Builds a request line according to HTTP/1.1 specs. Activate quirks mode to work outside specs.
  • buildUri() public
    Takes a $uri array and turns it into a fully qualified URL string
  • configUri() public
    Parses and sets the specified URI into current request configuration.
  • decodeBody() public

    Generic function to decode a $body with a given $encoding. Returns either an array with the keys 'body' and 'header' or false on failure.

  • decodeChunkedBody() public

    Decodes a chunked message $body and returns either an array with the keys 'body' and 'header' or false as a result.

  • delete() public
    Issues a DELETE request to the specified URI, query, and request.
  • escapeToken() public
    Escapes a given $token according to RFC 2616 (HTTP 1.1 specs)
  • get() public
    Issues a GET request to the specified URI, query, and request.
  • httpSerialize() public
    Serializes an array for transport.
  • loadCookies() public
    undocumented function
  • parseCookies() public
    undocumented function
  • parseHeader() public
    Parses an array based header.
  • parseQuery() public

    This function can be thought of as a reverse to PHP5's http_build_query(). It takes a given query string and turns it into an array and supports nesting by using the php bracket syntax. So this menas you can parse queries like:

  • parseResponse() public
    Parses the given message and breaks it down in parts.
  • parseUri() public

    Parses the given URI and breaks it down into pieces as an indexed array with elements such as 'scheme', 'port', 'query'.

  • post() public
    Issues a POST request to the specified URI, query, and request.
  • put() public
    Issues a PUT request to the specified URI, query, and request.
  • request() public
    Issue the specified request.
  • reset() public

    Resets the state of this HttpSocket instance to it's initial state (before Object::__construct got executed) or does the same thing partially for the request and the response property only.

  • saveCookies() public
    undocumented function
  • unescapeToken() public
    Unescapes a given $token according to RFC 2616 (HTTP 1.1 specs)
  • url() public
    undocumented function

Method Detail

__construct() public ¶

__construct( array $config = array() )

Build an HTTP Socket using the specified configuration.

Parameters
array $config optional array()
Configuration
Overrides
CakeSocket::__construct()

__tokenEscapeChars() public ¶

__tokenEscapeChars( boolean $hex = true , $chars = null )

Gets escape chars according to RFC 2616 (HTTP 1.1 specs).

Parameters
boolean $hex optional true
true to get them as HEX values, false otherwise
$chars optional null
Returns
array
Escape chars

buildCookies() public ¶

buildCookies( unknown $cookies )

undocumented function

Parameters
unknown $cookies

buildHeader() public ¶

buildHeader( array $header , $mode = 'standard' )

Builds the header.

Parameters
array $header
Header to build
$mode optional 'standard'
Returns
string
Header built from array

buildRequestLine() public ¶

buildRequestLine( array $request = array() , string $versionToken = 'HTTP/1.1' )

Builds a request line according to HTTP/1.1 specs. Activate quirks mode to work outside specs.

Parameters
array $request optional array()
Needs to contain a 'uri' key. Should also contain a 'method' key, otherwise defaults to GET.
string $versionToken optional 'HTTP/1.1'
The version token to use, defaults to HTTP/1.1
Returns
string
Request line

buildUri() public ¶

buildUri( array $uri = array() , string $uriTemplate = '%scheme://%user:%pass@%host:%port/%path?%query#%fragment' )

Takes a $uri array and turns it into a fully qualified URL string

Parameters
array $uri optional array()
A $uri array, or uses $this->config if left empty
string $uriTemplate optional '%scheme://%user:%pass@%host:%port/%path?%query#%fragment'
The Uri template/format to use
Returns
string
A fully qualified URL formated according to $uriTemplate

configUri() public ¶

configUri( mixed $uri = null )

Parses and sets the specified URI into current request configuration.

Parameters
mixed $uri optional null
URI (see HttpSocket::parseUri())
Returns
array
Current configuration settings

decodeBody() public ¶

decodeBody( string $body , mixed $encoding = 'chunked' )

Generic function to decode a $body with a given $encoding. Returns either an array with the keys 'body' and 'header' or false on failure.

Parameters
string $body
A string continaing the body to decode
mixed $encoding optional 'chunked'
Can be false in case no encoding is being used, or a string representing the encoding
Returns
mixed
Array or false

decodeChunkedBody() public ¶

decodeChunkedBody( string $body )

Decodes a chunked message $body and returns either an array with the keys 'body' and 'header' or false as a result.

Parameters
string $body
A string continaing the chunked body to decode
Returns
mixed
Array or false

delete() public ¶

delete( mixed $uri = null , array $data = array() , array $request = array() )

Issues a DELETE request to the specified URI, query, and request.

Parameters
mixed $uri optional null
URI to request (see HttpSocket::parseUri())
array $data optional array()
$query Query to append to URI
array $request optional array()
An indexed array with indexes such as 'method' or uri
Returns
mixed
Result of request

escapeToken() public ¶

escapeToken( string $token , $chars = null )

Escapes a given $token according to RFC 2616 (HTTP 1.1 specs)

Parameters
string $token
Token to escape
$chars optional null
Returns
string
Escaped token

get() public ¶

get( mixed $uri = null , array $query = array() , array $request = array() )

Issues a GET request to the specified URI, query, and request.

Parameters
mixed $uri optional null
URI to request (see HttpSocket::parseUri())
array $query optional array()
Query to append to URI
array $request optional array()
An indexed array with indexes such as 'method' or uri
Returns
mixed
Result of request

httpSerialize() public ¶

httpSerialize( array $data = array() )

Serializes an array for transport.

Parameters
array $data optional array()
Data to serialize
Returns
string
Serialized variable

loadCookies() public ¶

loadCookies( )

undocumented function

parseCookies() public ¶

parseCookies( unknown $header )

undocumented function

Parameters
unknown $header

parseHeader() public ¶

parseHeader( array $header )

Parses an array based header.

Parameters
array $header
Header as an indexed array (field => value)
Returns
array
Parsed header

parseQuery() public ¶

parseQuery( mixed $query )

This function can be thought of as a reverse to PHP5's http_build_query(). It takes a given query string and turns it into an array and supports nesting by using the php bracket syntax. So this menas you can parse queries like:

  • ?key[subKey]=value
  • ?key[]=value1&key[]=value2

A leading '?' mark in $query is optional and does not effect the outcome of this function. For the complete capabilities of this implementation take a look at HttpSocketTest::testParseQuery()

Parameters
mixed $query
A query string to parse into an array or an array to return directly "as is"
Returns
array
The $query parsed into a possibly multi-level array. If an empty $query is given, an empty array is returned.

parseResponse() public ¶

parseResponse( string $message )

Parses the given message and breaks it down in parts.

Parameters
string $message
Message to parse
Returns
array
Parsed message (with indexed elements such as raw, status, header, body)

parseUri() public ¶

parseUri( string $uri = null , mixed $base = array() )

Parses the given URI and breaks it down into pieces as an indexed array with elements such as 'scheme', 'port', 'query'.

Parameters
string $uri optional null
URI to parse
mixed $base optional array()
If true use default URI config, otherwise indexed array to set 'scheme', 'host', 'port', etc.
Returns
array
Parsed URI

post() public ¶

post( mixed $uri = null , array $data = array() , array $request = array() )

Issues a POST request to the specified URI, query, and request.

Parameters
mixed $uri optional null
URI to request (see HttpSocket::parseUri())
array $data optional array()
$query Query to append to URI
array $request optional array()
An indexed array with indexes such as 'method' or uri
Returns
mixed
Result of request

put() public ¶

put( mixed $uri = null , array $data = array() , array $request = array() )

Issues a PUT request to the specified URI, query, and request.

Parameters
mixed $uri optional null
URI to request (see HttpSocket::parseUri())
array $data optional array()
$query Query to append to URI
array $request optional array()
An indexed array with indexes such as 'method' or uri
Returns
mixed
Result of request

request() public ¶

request( mixed $request = array() )

Issue the specified request.

Parameters
mixed $request optional array()
Either an URI string, or an array defining host/uri
Returns
mixed
false on error, request body on success

reset() public ¶

reset( boolean $full = true )

Resets the state of this HttpSocket instance to it's initial state (before Object::__construct got executed) or does the same thing partially for the request and the response property only.

Parameters
boolean $full optional true
If set to false only HttpSocket::response and HttpSocket::request are reseted
Returns
boolean
True on success
Overrides
CakeSocket::reset()

saveCookies() public ¶

saveCookies( )

undocumented function

unescapeToken() public ¶

unescapeToken( string $token , $chars = null )

Unescapes a given $token according to RFC 2616 (HTTP 1.1 specs)

Parameters
string $token
Token to unescape
$chars optional null
Returns
string
Unescaped token

url() public ¶

url( unknown $url = null , unknown $uriTemplate = null )

undocumented function

Parameters
unknown $url optional null
unknown $uriTemplate optional null

Methods inherited from CakeSocket

__destruct() public ¶

__destruct( )

Destructor, used to disconnect from current connection.

abort() public ¶

abort( )

Abort socket operation.

Returns
boolean
Success

address() public ¶

address( )

Get the IP address of the current connection.

Returns
string
IP address

addresses() public ¶

addresses( )

Get all IP addresses associated with the current connection.

Returns
array
IP addresses

connect() public ¶

connect( )

Connect the socket to the given host and port.

Returns
boolean
Success

disconnect() public ¶

disconnect( )

Disconnect the socket from the current connection.

Returns
boolean
Success

host() public ¶

host( )

Get the host name of the current connection.

Returns
string
Host name

lastError() public ¶

lastError( )

Get the last error as a string.

Returns
string
Last error

read() public ¶

read( integer $length = 1024 )

Read data from the socket. Returns false if no data is available or no connection could be established.

Parameters
integer $length optional 1024
Optional buffer length to read; defaults to 1024
Returns
mixed
Socket data

setLastError() public ¶

setLastError( integer $errNum , string $errStr )

Set the last error.

Parameters
integer $errNum
Error code
string $errStr
Error string

write() public ¶

write( string $data )

Write data to the socket.

Parameters
string $data
The data to write to the socket
Returns
boolean
Success

Methods inherited from Object

Object() public ¶

Object( )

A hack to support __construct() on PHP 4 Hint: descendant classes have no PHP4 class_name() constructors, so this constructor gets called first and calls the top-layer __construct() which (if present) should call parent::__construct()

Returns
Object

__openPersistent() public ¶

__openPersistent( string $name , string $type = null )

Open the persistent class file for reading Used by Object::_persist()

Parameters
string $name
Name of persisted class
string $type optional null
Type of persistance (e.g: registry)

_persist() public ¶

_persist( string $name , string $return , $object , $type = null )

Checks for a persistent class file, if found file is opened and true returned If file is not found a file is created and false returned If used in other locations of the model you should choose a unique name for the persistent file There are many uses for this method, see manual for examples

Parameters
string $name
name of the class to persist
string $return
$object the object to persist
$object
$type optional null
Returns
boolean
Success

_savePersistent() public ¶

_savePersistent( string $name , object $object )

You should choose a unique name for the persistent file

There are many uses for this method, see manual for examples

Parameters
string $name
name used for object to cache
object $object
the object to persist
Returns
boolean
true on save, throws error if file can not be created

_set() public ¶

_set( array $properties = array() )

Allows setting of multiple properties of the object in a single line of code.

Parameters
array $properties optional array()
An associative array containing properties and corresponding values.

_stop() public ¶

_stop( $status = 0 )

Stop execution of the current script

Parameters
$status optional 0
http://php.net/exit for values

cakeError() public ¶

cakeError( string $method , array $messages = array() )

Used to report user friendly errors. If there is a file app/error.php or app/app_error.php this file will be loaded error.php is the AppError class it should extend ErrorHandler class.

Parameters
string $method
Method to be called in the error class (AppError or ErrorHandler classes)
array $messages optional array()
Message that is to be displayed by the error class
Returns
error
message

dispatchMethod() public ¶

dispatchMethod( string $method , array $params = array() )

Calls a method on this object with the given parameters. Provides an OO wrapper for call_user_func_array, and improves performance by using straight method calls in most cases.

Parameters
string $method
Name of the method to call
array $params optional array()
Parameter list to use when calling $method
Returns
mixed
Returns the result of the method call

log() public ¶

log( string $msg , integer $type = LOG_ERROR )

API for logging events.

Parameters
string $msg
Log message
integer $type optional LOG_ERROR
Error type constant. Defined in app/config/core.php.
Returns
boolean
Success of log write

requestAction() public ¶

requestAction( mixed $url , array $extra = array() )

Calls a controller's method from any location.

Parameters
mixed $url
String or array-based url.
array $extra optional array()
if array includes the key "return" it sets the AutoRender to true.
Returns
mixed

Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.


toString() public ¶

toString( )

Object-to-string conversion. Each class can override this method as necessary.

Returns
string
The name of this class

Properties detail

$config ¶

public array

Default configuration settings for the HttpSocket

array(
    'persistent' => false,
    'host'       => 'localhost',
    'protocol'   => 'tcp',
    'port'       => 80,
    'timeout'    => 30,
    'request' => array(
        'uri' => array(
            'scheme' => 'http',
            'host' => 'localhost',
            'port' => 80
        ),
        'auth' => array(
            'method' => 'Basic',
            'user' => null,
            'pass' => null
        ),
        'cookies' => array()
    )
)

$description ¶

public string

Object description

'HTTP-based DataSource Interface'

$lineBreak ¶

public string

String that represents a line break.

"\r\n"

$quirksMode ¶

public boolean

When one activates the $quirksMode by setting it to true, all checks meant to enforce RFC 2616 (HTTP/1.1 specs) will be disabled and additional measures to deal with non-standard responses will be enabled.

false

$request ¶

public array

The default values to use for a request

array(
    'method' => 'GET',
    'uri' => array(
        'scheme' => 'http',
        'host' => null,
        'port' => 80,
        'user' => null,
        'pass' => null,
        'path' => null,
        'query' => null,
        'fragment' => null
    ),
    'auth' => array(
        'method' => 'Basic',
        'user' => null,
        'pass' => null
    ),
    'version' => '1.1',
    'body' => '',
    'line' => null,
    'header' => array(
        'Connection' => 'close',
        'User-Agent' => 'CakePHP'
    ),
    'raw' => null,
    'cookies' => array()
)

$response ¶

public array

The default structure for storing the response

array(
    'raw' => array(
        'status-line' => null,
        'header' => null,
        'body' => null,
        'response' => null
    ),
    'status' => array(
        'http-version' => null,
        'code' => null,
        'reason-phrase' => null
    ),
    'header' => array(),
    'body' => '',
    'cookies' => array()
)
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs