本文整理汇总了PHP中Connection::send方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::send方法的具体用法?PHP Connection::send怎么用?PHP Connection::send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection::send方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* actually sends a message to to the daemon and returns the sent message
*
* @param string $key
* @param int $value
* @param string $type
* @param int $sampleRate
*/
private function send($key, $value, $type, $sampleRate)
{
if (strlen($this->namespace) != 0) {
$key = sprintf('%s.%s', $this->namespace, $key);
}
$message = sprintf("%s:%s|%s", $key, $value, $type);
$sample = mt_rand() / mt_getrandmax();
if ($sample > $sampleRate) {
return;
}
// overwrite sampleRate if all metrics should be sampled
if ($this->sampleRateAllMetrics < 1) {
$sampleRate = $this->sampleRateAllMetrics;
}
if ($sampleRate < 1) {
$sampledData = sprintf('%s|@%s', $message, $sampleRate);
} else {
$sampledData = $message;
}
if (!$this->isBatch) {
$this->connection->send($sampledData);
} else {
$this->batch[] = $sampledData;
}
}
示例2: truncate
/**
* @param string $_table
*/
public function truncate($_table)
{
/* ## LOGGER ## */
if (isset($this->logger)) {
$this->logger->DEBUG('truncate: ' . $_table);
}
if (empty($_table)) {
throw new UndefinedTabelException('null');
}
$table = $this->connection->escape($_table);
$sql = 'TRUNCATE TABLE `' . $table . '`';
$result = $this->connection->send($sql);
}
示例3: delete
/**
* @param string $_index
*/
public function delete($_index)
{
/* ## LOGGER ## */
if (isset($this->logger)) {
$this->logger->DEBUG('delete');
}
if (empty($_index)) {
throw new UndefinedRowException('null');
}
$table = $this->connection->escape($this->table);
$primary = $this->connection->escape($this->primary);
$index = $this->connection->escape($_index);
$sql = 'DELETE FROM `' . $table . '` WHERE `' . $primary . '` = \'' . $index . '\';';
$result = $this->connection->send($sql);
if ($this->connection->getAffectedRows() <= 0) {
throw new UndefinedRowException('undefined ' . $primary . '=' . $index);
}
}
示例4: jobFail
/**
* Mark your job as failing
*
* If your job fails for some reason (e.g. a query fails) you need to run
* this function and exit from your run() method. This will tell Gearman
* (and the client by proxy) that the job has failed.
*
* @param resource $socket
* @param string $handle
*
* @see Net\Gearman\Connection::send()
*/
private function jobFail($socket, $handle)
{
Connection::send($socket, 'work_fail', array('handle' => $handle));
}
示例5: endBatch
/**
* ends batch-send-recording and sends the recorded messages to the connection
*
* @return void
*/
public function endBatch()
{
$this->_isBatch = false;
$this->_connection->send(join("\n", $this->_batch));
$this->_batch = array();
}
示例6: submitTask
/**
* Submit a task to Gearman
*
* @param Task $task Task to submit to Gearman
*
* @return void
* @see \Net\Gearman\Task, \Net\Gearman\Client::runSet()
*/
protected function submitTask(Task $task)
{
switch ($task->type) {
case Task::JOB_LOW:
$type = 'submit_job_low';
break;
case Task::JOB_LOW_BACKGROUND:
$type = 'submit_job_low_bg';
break;
case Task::JOB_HIGH_BACKGROUND:
$type = 'submit_job_high_bg';
break;
case Task::JOB_BACKGROUND:
$type = 'submit_job_bg';
break;
case Task::JOB_EPOCH:
$type = 'submit_job_epoch';
break;
case Task::JOB_HIGH:
$type = 'submit_job_high';
break;
default:
$type = 'submit_job';
break;
}
$arg = $task->arg;
$params = array('func' => $task->func, 'uniq' => $task->uniq, 'arg' => $arg);
if ($task->type == Task::JOB_EPOCH) {
$params['epoch'] = $task->epoch;
}
$s = $this->getConnection();
Connection::send($s, $type, $params);
if (!is_array(Connection::$waiting[(int) $s])) {
Connection::$waiting[(int) $s] = array();
}
array_push(Connection::$waiting[(int) $s], $task);
}