xobotyi / beansclient Goto Github PK
View Code? Open in Web Editor NEWRobust PHP client for beanstalkd work queue
License: MIT License
Robust PHP client for beanstalkd work queue
License: MIT License
When I ->reserve(), I expect to get the next job; however, when my payloads get large (~16300 characters), the reservation just hangs and nothing happens. If I kill the script, and restart it, the same thing happens.
I'm running beanstalkd via a docker container:
schickling/beanstalkd
I've downloaded and installed the related beanstalkd-console docker, and it seems to pull the payload OK, and if I use the command line tools (beanstalk-cli) then it also can pull the payload.
Here is a script I use to replicate
<?php
if (PHP_SAPI !== 'cli') die('NO');
require __DIR__ . '/vendor/autoload.php';
use xobotyi\beansclient\BeansClient;
use xobotyi\beansclient\Connection;
$str = "a";
for ($i=0;$i<15280;$i++) {
$str.='a'; //lets build a really long string
}
$connection = new Connection('10.15.21.49', '11300', 2, false);
$beansClient = new BeansClient($connection);
$loop = 0;
$s = $beansClient->stats();
print_r($s);
while ($loop < 1500 ) {
$loop++;
$str .= 'a'; //slowly increase the size of the string
echo strlen($str);
echo "\n";
echo "Putting job\n";
$beansClient->useTube('default')->put($str);
echo "Getting job\n";
$job = $beansClient->watchTube('default')->reserve();
$id = $job->id;
if (empty($id)) echo "No jobs...and timedout\n";
else echo "Job is is " . $id . "\n";
if ($id) {
echo "\n";
$len = strlen($job->payload);
echo "\n";
echo $len;
echo "\n";
$beansClient->delete($id);
} else {
die('ooops');
}
}
dev
branchExamples of beansclient\Serializer has the below reference:
use xobotyi\beansclient\Serializer\Json;
$client = new BeansClient(new Connection(), new Json());
which is wrong since the class name is JsonSerializer, the correct one should be.
use xobotyi\beansclient\Serializer\JsonSerializer;
$client = new BeansClient(new Connection(), new JsonSerializer());
PHP Fatal error: Uncaught xobotyi\beansclient\Exception\Command: Got unexpected status code [DEADLINE_SOON] in /home/Serve/Resque/vendor/xobotyi/beansclient/src/Command/Reserve.php:65
Stack trace:
#0 /home/Serve/Resque/vendor/xobotyi/beansclient/src/BeansClient.php(122): xobotyi\beansclient\Command\Reserve->parseResponse(Array, NULL)
#1 /home/Serve/Resque/vendor/xobotyi/beansclient/src/BeansClient.php(304): xobotyi\beansclient\BeansClient->dispatchCommand(Object(xobotyi\beansclient\Command\Reserve))
#2 /home/Serve/Resque/lib/src/Resque/Serve.php(46): xobotyi\beansclient\BeansClient->reserve()
#3 {main}
thrown in /home/Serve/Resque/vendor/xobotyi/beansclient/src/Command/Reserve.php on line 65
Bug causing a fatal error
PHP Fatal error: Uncaught xobotyi\beansclient\Exception\Command: Got unexpected status code [DEADLINE_SOON] in /data/beta/websocket/vendor/xobotyi/beansclient/src/Command/Reserve.php:65
Stack trace:
#0 /data/beta/websocket/vendor/xobotyi/beansclient/src/BeansClient.php(122): xobotyi\beansclient\Command\Reserve->parseResponse(Array, NULL)
#1 /data/beta/websocket/vendor/xobotyi/beansclient/src/BeansClient.php(304): xobotyi\beansclient\BeansClient->dispatchCommand(Object(xobotyi\beansclient\Command\Reserve))
#2 /data/beta/websocket/bin/wsbs-worker.php(30): xobotyi\beansclient\BeansClient->reserve(30)
#3 /data/beta/websocket/bin/wsbs-worker.php(261): BeanstalkdWorker->run()
#4 {main
It should understand "[DEADLINE_SOON]" which is in beanstalkd 1.10
dev
branchwhile (true) {
try {
$job = $beansClient->watchTube('Order')
->reserve();
$payload = $job->payload;
if (!empty($payload))
{
var_dump($job->payload);
}
} catch (\Exception $ex) {
var_dump($ex->getTraceAsString());
var_dump($beansClient->getConnection()->isActive());
exit;
}
}
Backtrace:
string(406) "#0 /home/Serve/Resque/vendor/xobotyi/beansclient/src/BeansClient.php(122): xobotyi\beansclient\Command\Reserve->parseResponse(Array, NULL)
#1 /home/Serve/Resque/vendor/xobotyi/beansclient/src/BeansClient.php(304): xobotyi\beansclient\BeansClient->dispatchCommand(Object(xobotyi\beansclient\Command\Reserve))
#2 /home/Serve/Resque/app/test/stalk.php(24): xobotyi\beansclient\BeansClient->reserve()
#3 {main}"
bool(true)
Добрый день. Сделайте задание этого параметра самостоятельно. Так как сервер позволяет изменить максимальный размер тела сообщения. У меня например все данные не влазят, поэтому скрипт выкидывает исключение постоянно. Измените это с константы на статическую переменную. Спасибо!
Line 11 in 1d0318a
Sample code snippet does not work and throws exception;
PHP Fatal error: Uncaught xobotyi\beansclient\Exception\SocketException: Host `/tmp/beanstalkd.sock` not exists or unreachable in /beans/vendor/xobotyi/beansclient/src/Socket/SocketSocket.php:32
Stack trace:
#0 /beans/vendor/xobotyi/beansclient/src/Socket/SocketFactory.php(120): xobotyi\beansclient\Socket\SocketSocket->__construct('/tmp/beanstalkd...', -1, 2)
#1 /beans/vendor/xobotyi/beansclient/src/Connection.php(34): xobotyi\beansclient\Socket\SocketFactory->createSocket()
#2 /beans/writer.php(9): xobotyi\beansclient\Connection->__construct('/tmp/beanstalkd...', -1)
------
root@box:~/beans$ ls -l /tmp/beanstalkd.sock
srwxr-xr-x 1 root root 0 Mar 27 06:21 /tmp/beanstalkd.sock
Hi
Is there peek-buried command in the library to query the buried jobs?
I looked at the BeansClient class and I can only see a Peak method but it expects job id.
I am using the version 2 code.
This is a bug report.
When reserving a job using $client->reserve();
, an unknown error gets thrown when the queue is empty.
According to the documentation (and the source code), an empty queue should not throw an error, but instead result in a Job with id=null.
$client = new BeansClient(new Connection());
$client->watchTube('Project.Orders');
$job = $client->reserve(30);
// Exception: Unknown error in [/xobotyi/beansclient/src/Socket/SocketBase.php, line 158]
Stack Trace:
#0 /vendor/xobotyi/beansclient/src/Socket/SocketBase.php(175): xobotyi\beansclient\Socket\SocketBase->throwLastError()
#1 /vendor/xobotyi/beansclient/src/Connection.php(120): xobotyi\beansclient\Socket\SocketBase->readLine()
#2 /vendor/xobotyi/beansclient/src/BeansClient.php(76): xobotyi\beansclient\Connection->readLine()
#3 /vendor/xobotyi/beansclient/src/BeansClient.php(317): xobotyi\beansclient\BeansClient->dispatchCommand(Object(xobotyi\beansclient\Command\Reserve))
#4 /src/Command/OrdersCommand.php(30): xobotyi\beansclient\BeansClient->reserve(30)
[...]
Versions i'm using:
Как получить что то в echo на клиенте до того как завершит работу воркер?
Клиент
$job = $beansClient->useTube('myAwesomeTube') ->put($data); echo "ok";
Воркер
$job = $beansClient->watchTube('myAwesomeTube') ->reserve(); if ($job) { $data1 = unserialize($job->payload); $job->release(BeansClient::DEFAULT_PRIORITY, 600);
echo "ok"; я получаю только через 10 минут, а как можно получить сразу?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.