Httpsqs Client
The PHP client uses httpsqs:
A. php client extension (provided by a third party, visit: http://code.google.com/p/php-httpsqs-client/ for details)
I. Installation instructions
CD/usr/local
Mkdir php_httpsqs_client
CD php_httpsqs_client
: Wget http://php-httpsqs-client.googlecode.com/files/php_httpsqs_client_0.2.1.tar.gz
Tar zxvf php_httpsqs_client_0.2.1.tar.gz
/Usr/local/PHP/bin/phpize
./Configure -- enable-httpsqs -- With-PHP-Config =/usr/local/PHP/bin/PHP-config
Make & make install
# Add a line in PHP. ini
Extension = httpsqs. So;
Restart Apache
/Usr/local/Apache/bin/apachectl restart
View phpinfo (). If httpsqs exists, the configuration is successful;
2. Use httpsqs instances in the program
// Fetch data daemon
// Method 1: function call
$ HR = httpsqs_connect ($ host, $ port );
While (1 ){
$ DATA = httpsqs_get ($ HR, $ queuename, $ charset );
If ($ DATA = false ){
Sleep (1 );
} Else {
// Do something...
}
}
// Method 1: object call
$ HR = newhttpsqs ($ host, $ port );
While (1 ){
$ DATA = $ HR-> get ($ queuename, $ charset );
If ($ DATA = false ){
Sleep (1 );
} Else {
// Do something...
}
}
// Write data
// Method 1: function call
$ HR = httpsqs_connect ($ Hort, $ port );
Httpsqs_put ($ HR, $ queuename, $ data, $ charset );
// Method 1: object call
$ HR = newhttpsqs ($ Hort, $ port );
$ HR-> put ($ queuename, $ data, $ charset );
Iii. Function Description
/**
* Create an httpsqs connection
* @ Param string $ host server address, which can be blank. The default value is 127.0.0.1.
* @ Param int $ port the server port. It can be blank. The default value is 1218.
* @ Return Resource
*/
$ HR = httpsqs_connect ("Fig", 1218 );
/**
* Write queue data
* @ Param resource $ HR server connection handle
* @ Param string $ queue name
* @ Param string $ data write data
* @ Param string $ charset character set, which can be null. The default value is UTF-8.
* @ Return Boolean
*/
$ Putres = httpsqs_put ($ HR, "testqueue", "this is a test data", "UTF-8 ");
/**
* Get the last row of data in the queue
* @ Param resource $ HR
* @ Param string $ queue
* @ Param Boolean $ return_array whether to return an array. It can be null. The default value is false.
Returned array format: array ('pos' => 'queue insertion point', 'data' => 'data value ')
* @ Param string $ charset can be empty
* @ Return mixed
*/
$ Content = httpsqs_get ($ HR, "testqueue", true, "UTF-8 ");
/**
* Get the queue status
* @ Param resource $ HR
* @ Param string $ queue
* @ Param Boolean $ return_json whether the returned status is in JSON format. It can be blank. The default value is false.
* @ Return string
*/
$ Status = httpsqs_status ($ HR, "testqueue", true );
/**
* Get the data of a certain point in the queue
* @ Param resource $ HR
* @ Param string $ queue
* @ Param int $ position of the data to be obtained by POS
* @ Param string $ charset can be empty
* @ Return string
*/
$ Posdata = httpsqs_view ($ HR, "testqueue", 10, "UTF-8 ");
/**
* Queue Reset
* @ Param resource $ HR
* @ Param string $ queue
* @ Return Boolean
*/
$ Resetres = httpsqs_reset ($ HR, "testqueue ");
/**
* Set the maximum number of data entries in the queue.
* @ Param resource $ HR
* @ Param string $ queue
* @ Param int $ maximum number of data entries in the maxqueue queue
* @ Return Boolean
*/
$ Maxqueueres = httpsqs_maxqueue ($ HR, "testqueue", 10000 );
/**
* Modify the interval between regularly refreshing the memory buffer content to the disk
* @ Param resource $ HR
* @ Param string $ queue
* @ Param int $ synctime Interval
* @ Return Boolean
*/
$ Synctimeres = httpsqs_synctime ($ HR, "testqueue", 10 );
Iv. object call
// The parameter corresponds to httpsqs_connect
$ HR = newhttpsqs ($ host, $ port );
// The parameter corresponds to httpsqs_get
$ HR-> get ($ queuename, $ return_array, $ charset );
// The parameter corresponds to httpsqs_put
$ HR-> put ($ queuename, $ data, $ charset );
// The parameter corresponds to httpsqs_status
$ HR-> Status ($ queuename, $ return_json );
// The parameter corresponds to httpsqs_view
$ HR-> View ($ queuename, $ POS );
// The parameter corresponds to httpsqs_reset
$ HR-> Reset ($ queuename );
// The parameter corresponds to httpsqs_maxqueue
$ HR-> maxqueue ($ queuename );
// The parameter corresponds to httpsqs_synctime
$ HR-> synctime ($ queuename );
Functions and objects can be called;
B. Common PHP client files:
View PHP class source code: httpsqs_client.php (http://code.google.com/p/httpsqs/source/browse/trunk/client/php/httpsqs_client.php)
Usage:
<? PHP
......
Include_once ("httpsqs_client.php ");
$ Httpsqs = new httpsqs;
/* ----- Do not use the short connection mode of keep-alive -----*/
/* 1. Put text information into a queue. If the incoming queue is successful, the return value is Boolean: True. If the incoming queue fails, the return value is Boolean: false */
$ Result = $ httpsqs-> put ($ host, $ port, $ charset, $ name, $ data );
/* 2. Retrieve text information from a queue and return the content of the queue.
If no queue is unretrieved, the system returns the text: httpsqs_get_end
If an error occurs, the return value is Boolean: false.
*/
$ Result = $ httpsqs-> get ($ host, $ port, $ charset, $ name );
/* 3. retrieve text information from a queue and read point POS from the current queue return array example: array ("POS" => 7, "data" = & gt; "text message ") if no queue is unretrieved, an array is returned: array ("POS" => 0, "data" = & gt; "httpsqs_get_end"). If an error occurs, a Boolean value is returned: false */
$ Result = $ httpsqs-> gets ($ host, $ port, $ charset, $ name );
/* 4. view the queue status (normal mode )*/
$ Result = $ httpsqs-> Status ($ host, $ port, $ charset, $ name );
/* 5. return example: {"name": "queue_name", "maxqueue": 5000000, "putpos": 130, "putlap": 1, "getpos": 120, "getlap": 1, "unread": 10 }*/
$ Result = $ httpsqs-> status_json ($ host, $ port, $ charset, $ name );
/* 6. view the content at the specified queue location and return the content at the specified queue location. */
$ Result = $ httpsqs-> View ($ host, $ port, $ charset, $ name, $ POS );
/* 7. Reset the specified queue. If the queue is successfully reset, the return value is Boolean: True. If the queue fails to be reset, the return value is Boolean: false */
$ Result = $ httpsqs-> Reset ($ host, $ port, $ charset, $ name );
/* 8. Change the maximum number of queues of a specified queue. If the change is successful, the return value is Boolean: True. If the change operation is canceled, the return value is Boolean: false */
$ Result = $ httpsqs-> maxqueue ($ host, $ port, $ charset, $ name, $ num );
/* 9. If the interval between modifying and regularly refreshing the memory buffer content to the disk is modified successfully, a Boolean value is returned: True. If the change operation is canceled, a Boolean value is returned: false */
$ Result = $ httpsqs-> synctime ($ host, $ port, $ charset, $ name, $ num );
/* ----- Use the keep-alive persistent connection method (fast in command line mode )-----*/
$ Result = $ httpsqs-> pput ($ host, $ port, $ charset, $ name, $ data );
$ Result = $ httpsqs-> pget ($ host, $ port, $ charset, $ name );
$ Result = $ httpsqs-> pgets ($ host, $ port, $ charset, $ name );
$ Result = $ httpsqs-> pstatus ($ host, $ port, $ charset, $ name );
$ Result = $ httpsqs-> pstatus_json ($ host, $ port, $ charset, $ name );
$ Result = $ httpsqs-> pview ($ host, $ port, $ charset, $ name, $ POS );
$ Result = $ httpsqs-> preset ($ host, $ port, $ charset, $ name );
$ Result = $ httpsqs-> pmaxqueue ($ host, $ port, $ charset, $ name, $ num );
$ Result = $ httpsqs-> psynctime ($ host, $ port, $ charset, $ name, $ num );
?>