MediaWiki  1.23.1
SquidPurgeClient Class Reference

An HTTP 1.0 client built for the purposes of purging Squid and Varnish. More...

Public Member Functions

 __construct ( $server, $options=array())
 
 close ()
 Close the socket but allow it to be reopened for future purge requests. More...
 
 doReads ()
 Read some data. More...
 
 doWrites ()
 Perform pending writes. More...
 
 getReadSocketsForSelect ()
 Get read socket array for select() More...
 
 getWriteSocketsForSelect ()
 Get write socket array for select() More...
 
 isIdle ()
 
 queuePurge ( $url)
 Queue a purge operation. More...
 

Public Attributes

 $bodyRemaining
 
 $currentRequestIndex
 
 $host
 
 $ip
 
 $port
 
 $readBuffer
 
 $readState = 'idle'
 
 $requests = array()
 
 $socket
 The socket resource, or null for unconnected, or false for disabled due to error. More...
 
 $writeBuffer = ''
 
const BUFFER_SIZE = 8192
 
const EAGAIN = 11
 
const EINPROGRESS = 115
 
const EINTR = 4
 

Protected Member Functions

 getIP ()
 Get the host's IP address. More...
 
 getSocket ()
 Open a socket if there isn't one open already, return it. More...
 
 log ( $msg)
 
 markDown ()
 Close the socket and ignore any future purge requests. More...
 
 nextRequest ()
 
 processHeaderLine ( $line)
 
 processReadBuffer ()
 
 processStatusLine ( $line)
 

Detailed Description

An HTTP 1.0 client built for the purposes of purging Squid and Varnish.

Uses asynchronous I/O, allowing purges to be done in a highly parallel manner.

Could be replaced by curl_multi_exec() or some such.

Definition at line 30 of file SquidPurgeClient.php.

Constructor & Destructor Documentation

◆ __construct()

SquidPurgeClient::__construct (   $server,
  $options = array() 
)
Parameters
$serverstring
$optionsarray

Definition at line 56 of file SquidPurgeClient.php.

References port().

Member Function Documentation

◆ close()

SquidPurgeClient::close ( )

Close the socket but allow it to be reopened for future purge requests.

Definition at line 160 of file SquidPurgeClient.php.

References wfRestoreWarnings(), and wfSuppressWarnings().

Referenced by doReads(), and markDown().

◆ doReads()

SquidPurgeClient::doReads ( )

Read some data.

Call this when socket_select() indicates that the read buffer is non-empty.

Definition at line 255 of file SquidPurgeClient.php.

References $error, $socket, close(), getSocket(), log(), markDown(), processReadBuffer(), wfRestoreWarnings(), and wfSuppressWarnings().

◆ doWrites()

SquidPurgeClient::doWrites ( )

Perform pending writes.

Call this when socket_select() indicates that writing will not block.

Definition at line 220 of file SquidPurgeClient.php.

References $error, $flags, $socket, $writeBuffer, getSocket(), log(), markDown(), wfRestoreWarnings(), and wfSuppressWarnings().

◆ getIP()

SquidPurgeClient::getIP ( )
protected

Get the host's IP address.

Does not support IPv6 at present due to the lack of a convenient interface in PHP.

Definition at line 130 of file SquidPurgeClient.php.

References $host, $ip, IP\isIPv4(), IP\isIPv6(), wfRestoreWarnings(), and wfSuppressWarnings().

Referenced by getSocket().

◆ getReadSocketsForSelect()

SquidPurgeClient::getReadSocketsForSelect ( )

Get read socket array for select()

Returns
array

Definition at line 100 of file SquidPurgeClient.php.

References $socket, array(), and getSocket().

◆ getSocket()

SquidPurgeClient::getSocket ( )
protected

Open a socket if there isn't one open already, return it.

Returns false on error.

Returns
bool|resource

Definition at line 68 of file SquidPurgeClient.php.

References $error, $ip, $ok, $socket, getIP(), log(), markDown(), port(), wfRestoreWarnings(), and wfSuppressWarnings().

Referenced by doReads(), doWrites(), getReadSocketsForSelect(), and getWriteSocketsForSelect().

◆ getWriteSocketsForSelect()

SquidPurgeClient::getWriteSocketsForSelect ( )

Get write socket array for select()

Returns
array

Definition at line 115 of file SquidPurgeClient.php.

References $socket, array(), and getSocket().

◆ isIdle()

SquidPurgeClient::isIdle ( )
Returns
bool

Definition at line 213 of file SquidPurgeClient.php.

◆ log()

SquidPurgeClient::log (   $msg)
protected
Parameters
$msgstring

Definition at line 375 of file SquidPurgeClient.php.

References wfDebugLog().

Referenced by doReads(), doWrites(), getSocket(), and processStatusLine().

◆ markDown()

SquidPurgeClient::markDown ( )
protected

Close the socket and ignore any future purge requests.

This is called if there is a protocol error.

Definition at line 152 of file SquidPurgeClient.php.

References close().

Referenced by doReads(), doWrites(), getSocket(), and processStatusLine().

◆ nextRequest()

SquidPurgeClient::nextRequest ( )
protected

Definition at line 356 of file SquidPurgeClient.php.

References $currentRequestIndex, and key.

Referenced by processReadBuffer(), and queuePurge().

◆ processHeaderLine()

SquidPurgeClient::processHeaderLine (   $line)
protected
Parameters
$linestring

Definition at line 348 of file SquidPurgeClient.php.

References $line.

Referenced by processReadBuffer().

◆ processReadBuffer()

SquidPurgeClient::processReadBuffer ( )
protected
Exceptions
MWException
Returns
string

Definition at line 286 of file SquidPurgeClient.php.

References $lines, nextRequest(), processHeaderLine(), and processStatusLine().

Referenced by doReads().

◆ processStatusLine()

SquidPurgeClient::processStatusLine (   $line)
protected
Parameters
$line
Returns

Definition at line 329 of file SquidPurgeClient.php.

References $line, list, log(), and markDown().

Referenced by processReadBuffer().

◆ queuePurge()

SquidPurgeClient::queuePurge (   $url)

Queue a purge operation.

Parameters
$urlstring

Definition at line 178 of file SquidPurgeClient.php.

References $host, $path, array(), SquidUpdate\expand(), global, nextRequest(), Http\userAgent(), wfAppendQuery(), and wfParseUrl().

Member Data Documentation

◆ $bodyRemaining

SquidPurgeClient::$bodyRemaining

Definition at line 50 of file SquidPurgeClient.php.

◆ $currentRequestIndex

SquidPurgeClient::$currentRequestIndex

Definition at line 36 of file SquidPurgeClient.php.

Referenced by nextRequest().

◆ $host

SquidPurgeClient::$host

Definition at line 31 of file SquidPurgeClient.php.

Referenced by getIP(), and queuePurge().

◆ $ip

SquidPurgeClient::$ip

Definition at line 31 of file SquidPurgeClient.php.

Referenced by getIP(), and getSocket().

◆ $port

SquidPurgeClient::$port

Definition at line 31 of file SquidPurgeClient.php.

◆ $readBuffer

SquidPurgeClient::$readBuffer

Definition at line 48 of file SquidPurgeClient.php.

◆ $readState

SquidPurgeClient::$readState = 'idle'

Definition at line 33 of file SquidPurgeClient.php.

◆ $requests

SquidPurgeClient::$requests = array()

Definition at line 35 of file SquidPurgeClient.php.

◆ $socket

SquidPurgeClient::$socket

The socket resource, or null for unconnected, or false for disabled due to error.

Definition at line 46 of file SquidPurgeClient.php.

Referenced by doReads(), doWrites(), getReadSocketsForSelect(), getSocket(), and getWriteSocketsForSelect().

◆ $writeBuffer

SquidPurgeClient::$writeBuffer = ''

Definition at line 34 of file SquidPurgeClient.php.

Referenced by doWrites().

◆ BUFFER_SIZE

const SquidPurgeClient::BUFFER_SIZE = 8192

Definition at line 41 of file SquidPurgeClient.php.

◆ EAGAIN

const SquidPurgeClient::EAGAIN = 11

Definition at line 39 of file SquidPurgeClient.php.

◆ EINPROGRESS

const SquidPurgeClient::EINPROGRESS = 115

Definition at line 40 of file SquidPurgeClient.php.

◆ EINTR

const SquidPurgeClient::EINTR = 4

Definition at line 38 of file SquidPurgeClient.php.


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