php-httpsqs-client 的使用
安裝說明
mkdir php_httpsqs_client? cd php_httpsqs_client?
unzip php_httpsqs_0.1.zip? /usr/local/php/bin/phpize? ./configure --enable-httpsqs
--with-php-config=/usr/local/php/bin/php-config? make && make install?
#接著在php.ini中添加一行? extension=httpsqs.so;
函數說明
/**? ?* 建立httpsqs串連? ?* @param string $host 伺服器位址,可以為空白,預設為127.0.0.1? ?* @param int ? ?$port 伺服器連接埠,可以為空白,預設為1218? ?* @return resource? ?*/? $hr = httpsqs_connect("127.0.0.1", 1218);
/**? ?* 寫入隊列資料? ?* @param resource $hr ? ? ?伺服器串連控制代碼? ?* @param string ? $queue ? 隊列名稱? ?* @param string ? $data ? ?寫入資料? ?* @param string ? $charset 字元集,可以為空白,預設為utf-8? ?* @return boolean? ?*/?
$putRes = httpsqs_put($hr, "testQueue", "This is a test Data", "UTF-8");
/** ? ?* 擷取隊列最後一條資料? ?* @param resource $hr? ?* @param string ? $queue? ?* @param boolean ?$return_array 是否返回數組,可以為空白,預設為false? ? ? ? ? ? 返回數組格式:array('pos'=>'隊列插入點', 'data'=>'資料值')? ?* @param string ? $charset 可以為空白? ?* @return mixed? ?*/? $content = httpsqs_get($hr, "testQueue", true, "UTF-8");
/**? ?* 擷取隊列狀態? ?* @param resource $hr? ?* @param string ? $queue? ?* @param boolean ?$return_json 是否返回狀態的json格式,可以為空白,預設為false? ?* @return string? ?*/? $status = httpsqs_status($hr, "testQueue", true);
/**? ?* 擷取隊列某個點資料? ?* @param resource $hr? ?* @param string ? $queue? ?* @param int ? ? ?$pos 要擷取的某條資料的位置? ?* @param string ? $charset 可以為空白? ?* @return string? ?*/? $posData = httpsqs_view($hr, "testQueue", 10, "UTF-8");
/**? ?* 隊列重設? ?* @param resource $hr? ?* @param string ? $queue? ?* @return boolean? ?*/? $resetRes = httpsqs_reset($hr, "testQueue");
/**? ?* 設定隊列最大資料條數? ?* @param resource $hr? ?* @param string ? $queue? ?* @param int ? ? ?$maxqueue 隊列最大資料條數? ?* @return boolean? ?*/? $maxqueueRes = httpsqs_maxqueue($hr, "testQueue", 10000);
/**? ?* 修改定時重新整理記憶體緩衝區內容到磁碟的間隔時間? ?* @param resource $hr? ?* @param string ? $queue? ?* @param int ? ? ?$synctime 間隔時間? ?* @return boolean? ?*/? $synctimeRes = httpsqs_synctime($hr, "testQueue", 10);
對象調用
// 參數與httpsqs_connect對應? $hr = new HttpSQS($host, $port);? ? // 參數與httpsqs_get對應? $hr->get($queuename, $return_array, $charset);? ? // 參數與httpsqs_put對應? $hr->put($queuename, $data, $charset);? ? // 參數與httpsqs_status對應? $hr->status($queuename, $return_json);? ? // 參數與httpsqs_view對應? $hr->view($queuename, $pos);? ? // 參數與httpsqs_reset對應? $hr->reset($queuename);? ? // 參數與httpsqs_maxqueue對應? $hr->maxqueue($queuename);? ? // 參數與httpsqs_synctime對應? $hr->synctime($queuename);
樣本
// 取資料Daemon? $hr = httpsqs_connect($host, $port);? while (1) {? ? ?
$data = httpsqs_get($hr, $queuename, $charset);? ? ?
if ($data === false) {? ? ? ? ?sleep(1);? ? ? } else {? ? ? ? // do something...? ? ? }? }? ?
?// 或者? $hr = new HttpSQS($host, $port);? while (1) {? ? ? $data = $hr->get($queuename, $charset);? ? ?
?if ($data === false) {? ? ? ? ? sleep(1);? ? ? } else {? ? ? ? // do something...? ? ? }? }? ?
?// 寫資料? $hr = httpsqs_connect($hort, $port);? httpsqs_put($hr, $queuename, $data, $charset);? ?
?// 或者? $hr = new HttpSQS($hort, $port);? $hr->put($queuename, $data, $charset);