本文整理汇总了PHP中GearmanClient::do方法的典型用法代码示例。如果您正苦于以下问题:PHP GearmanClient::do方法的具体用法?PHP GearmanClient::do怎么用?PHP GearmanClient::do使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GearmanClient
的用法示例。
在下文中一共展示了GearmanClient::do方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: queueAssignment
/**
* This function will take 3 arguments and pass it to gearman worker to store in database
*/
function queueAssignment($name, $email, $phone)
{
$detailsArray = array('name' => $name, 'email' => $email, 'phone' => $phone);
$detailsStr = json_encode($detailsArray);
writeFile($detailsArray);
// client code
$client = new GearmanClient();
$client->addServer();
$store = $client->do("saveRecord", $detailsStr);
}
示例2: GearmanClient
* Copyright (C) 2008 James M. Luedke <contact@jamesluedke.com>,
* Eric Day <eday@oddments.org>
* All rights reserved.
*
* Use and distribution licensed under the PHP license. See
* the LICENSE file in this directory for full text.
*/
echo "Starting\n";
# Create our client object.
$gmclient = new GearmanClient();
# Add default server (localhost).
$gmclient->addServer();
echo "Sending job\n";
# Send reverse job
do {
$result = $gmclient->do("reverse", "Hello!");
# Check for various return packets and errors.
switch ($gmclient->returnCode()) {
case GEARMAN_WORK_DATA:
echo "Data: {$result}\n";
break;
case GEARMAN_WORK_STATUS:
list($numerator, $denominator) = $gmclient->doStatus();
echo "Status: {$numerator}/{$denominator} complete\n";
break;
case GEARMAN_SUCCESS:
break;
default:
echo "RET: " . $gmclient->returnCode() . "\n";
exit;
}
示例3: GearmanClient
<?php
/**
* Run the reverse function.
*
* @link http://de2.php.net/manual/en/gearman.examples-reverse.php
*/
$gmclient = new GearmanClient();
# Add default server (localhost).
$gmclient->addServer();
$function = 'reverse';
$data = 'Hello!';
do {
$result = $gmclient->do($function, $data);
switch ($gmclient->returnCode()) {
case GEARMAN_WORK_DATA:
echo "Data: {$result}\n";
break;
case GEARMAN_WORK_STATUS:
list($numerator, $denominator) = $gmclient->doStatus();
echo "Status: {$numerator}/{$denominator} complete\n";
break;
case GEARMAN_WORK_FAIL:
echo "Failed\n";
exit;
case GEARMAN_SUCCESS:
break;
default:
echo "RET: " . $gmclient->returnCode() . "\n";
exit;
}
示例4: GearmanClient
<?php
$client = new GearmanClient();
$client->addServer("10.0.0.6", 4730);
//echo $client->do("reverse", "Hello World!")."</br>";
echo $client->do("trackFedex", "510087020") . "</br>";
echo $client->do("trackUSPS", "9405509699937018835945") . "</br>";
//echo $client->do("trackUPS", "1Z6934X10351053020")."</br>";
//echo $client->do("trackDHL", "123456789012")."</br>";
示例5: executePaste
public function executePaste($id, $view = '', $ini = 'development')
{
$paste_dir = '/code';
$jail_dir = '/opt/codepad';
if (!$view) {
$view = 'html_body';
}
$file = "{$paste_dir}/{$id}";
if (file_exists("{$jail_dir}/{$file}")) {
$gearman = new GearmanClient();
$gearman->addServer();
$paste = DataObject::get_one('Paste', 'Filename = \'' . Convert::raw2SQL($id) . '\'');
if (!$paste) {
echo 'Paste not found';
die;
}
$func = $paste->PHPVersion()->FuncName;
$options['path'] = $file;
$options['headers'] = $this->emu_getallheaders();
$query = $_GET;
unset($query['url']);
$query = http_build_query($query);
$options['query_string'] = $query;
$options['method'] = $_SERVER['REQUEST_METHOD'];
// Attempt 1 of 3 - Fetch request body from STDIN via php://input
$options['body'] = file_get_contents('php://input');
if ($_SERVER['CONTENT_LENGTH'] > 0 && !$options['body']) {
// Attempt 2 of 3 - Fetch request body via PECL_HTTP extension
$options['body'] = http_get_request_body();
// Attempt 3 of 3 - Reconstruct request body from $_POST and $_FILES
if (!$options['body']) {
list($mime, $boundary) = explode('boundary=', $_SERVER['CONTENT_TYPE']) + array('', '');
if ($boundary) {
foreach ($_POST as $name => $value) {
$options['body'] .= "--{$boundary}\r\nContent-Disposition: form-data; name=\"{$name}\"\r\n\r\n{$value}\r\n";
}
foreach ($_FILES as $name => $file) {
$content = '||BASE64-BINARY||' . base64_encode(file_get_contents($file['tmp_name'])) . '||BASE64-BINARY||';
$type = $file['type'];
$length = $file['size'];
$origname = $file['name'];
$options['body'] .= "--{$boundary}\r\nContent-Disposition: form-data; name=\"{$name}\"; filename=\"{$origname}\"\r\nContent-Type: {$type}\r\nContent-Length: {$length}\r\nContent-Transfer-Encoding: binary\r\n\r\n{$content}\r\n";
}
$options['body'] .= "--{$boundary}";
}
}
}
$options['ini'] = $ini;
switch ($view) {
case 'request_headers':
echo '<pre>';
foreach ($options['headers'] as $header => $value) {
echo "{$header}: {$value}\r\n";
}
echo '</pre>';
die;
case 'request_body':
echo $options['body'];
die;
case 'opcodes':
$func = 'VLD';
// $options['version'] = $paste->PHPVersion()->Path;
break;
case 'profile':
echo 'Not yet implemented';
die;
case 'call_graph':
echo 'Not yet implemented';
die;
}
$res = $gearman->do($func, json_encode($options));
$result = (array) json_decode($res);
if (empty($result['headers'])) {
// No headers, treat as error response
if (!empty($result['errors'])) {
echo $result['errors'];
die;
}
if (strpos($result['body'], 'timelimit: sending warning signal 15') !== FALSE) {
var_dump($result);
echo "Time limit exceeded.";
} elseif ($view != 'opcodes') {
echo "Invalid HTTP Response from server, received:<br/>\n<pre>";
var_dump($res);
echo "</pre>";
die;
}
}
$headers = base64_decode($result['headers']);
$body = base64_decode($result['body']);
switch ($view) {
case 'html_body':
foreach (explode("\r\n", $headers) as $header) {
header($header);
}
echo $body;
die;
case 'response_body':
echo "<pre>{$body}</pre>";
die;
//.........这里部分代码省略.........
示例6: list
}
list($key, $value) = explode('=', $opt);
$params[$key] = $value;
}
}
return $params;
}
$options = getopt('f:hH:p:');
if (array_key_exists('h', $options)) {
help();
}
if (!array_key_exists('f', $options)) {
help(1);
}
if (!array_key_exists('H', $options)) {
$options['H'] = 'localhost';
}
if (!array_key_exists('p', $options)) {
$options['p'] = 4730;
}
$workload = parse_params($argv);
$host = $options['H'];
$port = $options['p'];
$function = $options['f'];
$workload = serialize($workload);
echo PHP_EOL, 'Starting gearman job request:', PHP_EOL;
echo "gearman -h {$host} -p {$port} -f {$function} '{$workload}'", PHP_EOL;
$client = new GearmanClient();
$client->addServer($host, $port);
$result = $client->do($function, $workload);
echo "Result: {$result}", PHP_EOL;
示例7: GearmanClient
<?php
// Reverse Client Code
$client = new GearmanClient();
$client->addServer('gqueue');
print $client->do('reverse', 'Hello World!') . PHP_EOL;
示例8: completeCallBack
<?php
$client = new GearmanClient();
$client->addServer('127.0.0.1', 4730);
//本机可以直接addServer(),默认服务器端使用4730端口
$client->setCompleteCallback('completeCallBack');
//先绑定才有效
$result1 = $client->do('say', 'do');
//do是同步进行,进行处理并返回处理结果。
$result2 = $client->doBackground('say', 'doBackground');
//异步进行,只返回处理句柄。
$result3 = $client->addTask('say', 'addTask');
//添加任务到队列,同步进行?通过添加task可以设置回调函数。
$result4 = $client->addTaskBackground('say', 'addTaskBackground');
//添加后台任务到队列,异步进行?
$client->runTasks();
//运行队列中的任务,只是do系列不需要runTask()。
echo 'result1:';
var_dump($result1);
echo '<br/>';
echo 'result2:';
var_dump($result2);
echo '<br/>';
echo 'result3:';
var_dump($result3);
echo '<br/>';
echo 'result4:';
var_dump($result4);
echo '<br/>';
//绑定回调函数,只对addTask有效
function completeCallBack($task)
示例9: GearmanClient
* Eric Day (eday@oddments.org)
*
* Use and distribution licensed under the PHP license. See
* the LICENSE file in this directory for full text.
*/
/* create our object */
$gmc = new GearmanClient();
/* add the default server */
$gmc->addServer();
$data['src'] = $_SERVER['argv'][1];
$data['dest'] = "small_" . $_SERVER['argv'][1];
$data['x'] = 200;
$data['y'] = NULL;
/* run reverse client */
do {
$value = $gmc->do("shrink_image", serialize($data));
switch ($gmc->returnCode()) {
case GEARMAN_WORK_DATA:
echo "DATA: {$value}\n";
break;
case GEARMAN_SUCCESS:
echo "SUCCESS: {$value}\n";
break;
case GEARMAN_WORK_STATUS:
list($numerator, $denominator) = $gmc->doStatus();
echo "Status: {$numerator}/{$denominator}\n";
break;
default:
echo "ERR: " . $gmc->error() . "\n";
}
} while ($gmc->returnCode() != GEARMAN_SUCCESS);
示例10: GearmanClient
<?php
$client = new GearmanClient();
$client->addServer();
print $client->do("reverse", $argv[1]) . "\n";
示例11: GearmanClient
<?php
$client = new GearmanClient();
$client->addServer("127.0.0.1", 4730);
$data = msgpack_pack(array('a' => 1, 'b' => 'str'));
$result = $client->do('echo', $data);
echo $result;
$result = $client->do('get_config', " ");
echo $result;
示例12: GearmanClient
<?php
$client = new GearmanClient();
$client->addServer('192.168.1.235', 4730);
echo $client->do('client_test', microtime()) . PHP_EOL;
示例13: GearmanClient
<?php
$client = new GearmanClient();
$client->addServer();
print "\nRunning test...";
print "\nReversing \"Hello World\" using reverse_worker ..... ";
print $client->do("reverse", "Hello World!");
print "\nComplete!\n\n";