Git Product home page Git Product logo

pecl-networking-gearman's Introduction

The Gearman PHP Extension provides a wrapper to libgearman. This
gives the user the ability to write fully featured Gearman clients
and workers in PHP, allowing them to quickly develop distributed
applications.

For more information about Gearman, see: http://www.gearman.org/

Requirements
    * For the 0.8.* versions, libgearman v0.14 or greater
    * For the 1.0.* versions, libgearman v0.21 or greater
    * For the 1.1.* versions, libgearman v1.1.0 or greater
    * For the 2.0.* versions, testing is done against libgearman v1.1.8 and PHP 7.0-7.4
    * For the 2.1.* versions, testing is done against libgearman v1.1.18 and PHP 7.0-8.3

The Gearman PHP Extension requires the Gearman C server and library package
to be installed. You can download the latest from:

https://github.com/gearman/gearmand/releases

See the README file in that package for installation instructions. Once
it is installed you can compile the Gearman PHP Extension. You'll need
to make sure you have the PHP development packages installed first
(if you have 'phpize' command you’re all set). You'll also probably
want the PHP command line interface installed as well (usually named
php-cli). After extracting the Gearman PHP tarball, just run:

phpize
./configure
make
make install

You then need to make PHP aware of the new extension by adding the
following line to your php.ini:

extension="gearman.so"

You can then test if the module is configured correctly with the
PHP cli:

php --info | grep gearman

To run a simple example

cd examples

1. Start the gearmand server in a separate terminal:

gearmand


2. In another terminal, change to this source directory and run:

php examples/reverse_worker.php


3. In another terminal, change to this source directory and run:

php examples/reverse_client.php


You should see some output from both the reverse client and worker
scripts about the status and then a final result.


Have fun!

http://pecl.php.net/package/gearman

pecl-networking-gearman's People

Contributors

andypost avatar atakde avatar bjori avatar bluetm avatar bolknote avatar chrisgoffinet avatar cracksalad avatar devinodaniel avatar esabol avatar felipensp avatar guilhermeblanco avatar hjr3 avatar jaredwilliams avatar keyurdg avatar oleg-st avatar oligriffiths avatar remicollet avatar rlerdorf avatar rosmo avatar sean-der avatar vesa-hirsimaa-crasman avatar wcgallego avatar wgallego-fastly avatar xalopp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pecl-networking-gearman's Issues

php: symbol lookup error: /usr/lib/php/20210902/gearman.so: undefined symbol: ZVAL_NEW_ARR

Got an error
php: symbol lookup error: /usr/lib/php/20210902/gearman.so: undefined symbol: ZVAL_NEW_ARR
while trying to run reverse_worker.php

libgearman8:amd64 1.1.18+ds-3.1ubuntu1

pecl extension: gearman 2.1.0 (stable)

Linux 5.11.0-41-generic #45~20.04.1-Ubuntu SMP Wed Nov 10 10:20:10 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

PHP 8.1.0 (cli) (built: Nov 25 2021 20:22:03) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.0, Copyright (c) Zend Technologies
with Zend OPcache v8.1.0, Copyright (c), by Zend Technologies

When will GearmanWorker::work be false?

I have looked everywhere (even tried reading the C source but that didn't help) but I can't find the answer to that.

When will GearmanWorker::work be false? What can/will cause it to "fail" basically?
The PHP manual over at php.net says:

Waits for a job to be assigned and then calls the appropriate callback function. Issues an E_WARNING with the last Gearman error if the return code is not one of GEARMAN_SUCCESS, GEARMAN_IO_WAIT, or GEARMAN_WORK_FAIL.

If the return code of what is not one of GEARMAN_SUCCESS, GEARMAN_IO_WAIT or GEARMAN_WORK_FAIL?

Is there a way to see the Gearman Worker class as a PHP code? I.e. as if it was a class written in PHP?

How to start a worker on reboot

Hello,
I'm new to Gearman. I've been able to write worker and client PhP scripts that successfully execute tasks.

Background:
I have also been trying to implement crontab on my gearman server so that the worker php scripts are loaded automatically on restarting the machine.

ie.
crontab -e
@reboot php /var/www/scripts_gearman/worker_one.php
@reboot php /var/www/scripts_gearman/worker_two.php

Observation (Using crontab)
While the scripts do load via crontab (see initial status) they are not stable. For example after running the client (ie. client_one) for worker_one the worker produces no result and upon reviewing its status (see reviewed status) no available workers are report.

Reboot
(crontab initializes gearman workers)

Initial status (on reboot):
gearadmin -h 127.0.0.1 -p 4730 --status
one 0 0 1
two 0 0 1

client one now called (triggering a worker one process)

Reviewed status (after client one called):
gearadmin -h 127.0.0.1 -p 4730 --status
one 0 0 0
two 0 0 1

Observation (using tutorial example)
The getting started tutorial here shows the php cli method for running a worker. This method is stable. For example after running the same client (ie. client_one) for worker_one the worker successfully produces a result and upon reviewing its status the worker continues to be available.

Initialize worker one
php /var/www/scripts_gearman/worker_one.php &

Initial status (after initializing worker one):
gearadmin -h 127.0.0.1 -p 4730 --status
one 0 0 1
two 0 0 1

client one now called (triggering a worker one process)

Reviewed status (after client one called):
gearadmin -h 127.0.0.1 -p 4730 --status
one 0 0 1
two 0 0 1

Question:
Is the crontab behavior expected? How can gearman workers be run correctly from crontab? What is the best way to initialize a worker on restarting a machine? Note the machine is a fresh ubuntu 24.04 server.

Gearman's introductory demo does not recognize the "do" function

Hello,

Some background and then the error followed by an observation:

Background:
I am running php 8.3 on a fresh ubuntu 24.04 lts server, hosted at AWS. After successfully installing Gearman and receiving the version per the php getting started instructions given here. I tried to run the first demo and received the following output.

Error:
_PHP Warning: Module "gearman" is already loaded in Unknown on line 0
PHP Fatal error: Uncaught Error: Call to undefined method GearmanClient::do() in /var/www/gc_gearman.php:4
Stack trace:
#0 {main}

Observation:
I then tried another example (the reverse example) from here, which worked without a problem. I believe there is a bug in the extension or the "do" command is old and requires updating.

Gearman client add server errors

Hello,

Some background, the error, and the client code used (ie. modification to add remote client).

Background:
I am a new Gearman user. I have a fresh machine running Ubuntu 24.04 on AWS with Gearman installed successfully as per the version test given here. I am running PHP 8.3.

I can run all the provided Gearman php demos on the server (note a recent issue logged about "do" as opposed to "doNormal"). I am now trying to send a Gearman job (the reverse hello world string demo) to a second server for processing. The servers are on the same subnet and can ping each other, there are no firewalls blocking traffic.

When sending the job I receive the following error:

Error:
PHP Fatal error: Uncaught GearmanException: Failed to set exception option in /var/www/client.php:7
Stack trace:
#0 /var/www/client.php(7): GearmanClient->addServer()
#1 {main}

Client code used (note modification to add remove client via addServer):
`<?php

// Create our client object
$client = new GearmanClient();

// Add a server (modified where X.X.X.X is the actual IP address of given machine)

$client->addServer('X.X.X.X','4730'); // by default host/port will be "localhost" & 4730

echo "Sending job\n";

// Send reverse job
$result = $client->doNormal("reverse", "Hello!");
if ($result) {
echo "Success: $result\n";
}
?>`

Observation:
Help is greatly appreciated. I do not know if this is an error from my end or a possible bug.

Error to install gearman with php 8.2

I'm trying to install gearman and receive the result below.

RUN pecl install gearman-2.1.0
4.260 pecl/gearman requires PHP (version >= 7.0.0, version <= 8.1.99, excluded versions: 6.0.0), installed version is 8.2.9
4.260 No valid packages found
4.260 install failed

Could you please relase a version with support for php 8.2 or help me how to proceed .

thank you.

What about publishing a new version on pecl?

The master branch contains the fix 7da13e4

Without that patch, we can't use this extension on PHP 8.1, since we have this issue:

Warning: PHP Startup: Unable to load dynamic library 'gearman' [...]
Error relocating [...]/gearman.so: ZVAL_NEW_ARR: symbol not found

Packet that is being freed has not been allocated, most likely this is do to freeing a gearman_task_st or other object twice

Could you explain please, what happened

libgearman/packet.cc:253 Assertion "packet->universal" failed for function "gearman_packet_free" likely for "Packet that is being freed has not been allocated, most likely this is do to freeing a gearman_task_st or other object twice"

Begin stack trace, frames found: 34
?0  0x7efcd4cf7f0f in /usr/local/lib/libgearman.so.8(+0x7f0f) [0x7efcd4cf7f0f]
?1  0x7efcd4d028e0 in /usr/local/lib/libgearman.so.8(+0x128e0) [0x7efcd4d028e0]
?2  0x7efcd4cfbf8d in /usr/local/lib/libgearman.so.8(+0xbf8d) [0x7efcd4cfbf8d]
?3  0x7efcd4cfbfed in /usr/local/lib/libgearman.so.8(+0xbfed) [0x7efcd4cfbfed]
?4  0x7efcd4d058a0 in /usr/local/lib/libgearman.so.8(+0x158a0) [0x7efcd4d058a0]
?5  0x7efcd4d058dd in /usr/local/lib/libgearman.so.8(+0x158dd) [0x7efcd4d058dd]
#6  0x7efcd4d08898 in gearman_worker_free at /usr/local/lib/libgearman.so.8
#7  0x7efcd4d2f831 in zim_GearmanWorker___destruct at /usr/lib/php/20200930/gearman.so
?8  0x7efcd7065499 in /usr/lib/php/20200930/xdebug.so(+0x16499) [0x7efcd7065499]
#9  0x5612e5d09452 in zend_call_function at php8.0
#10  0x5612e5d09705 in zend_call_known_function at php8.0
#11  0x5612e5d99a84 in zend_objects_destroy_object at php8.0
#12  0x5612e5d9e474 in zend_objects_store_del at php8.0
#13  0x5612e5d7dc7f in execute_ex at php8.0
?14  0x7efcd7064e3a in /usr/lib/php/20200930/xdebug.so(+0x15e3a) [0x7efcd7064e3a]
?15  0x5612e5b6007c in php8.0(+0x10a07c) [0x5612e5b6007c]
#16  0x5612e5d7fd89 in execute_ex at php8.0
?17  0x7efcd7064e3a in /usr/lib/php/20200930/xdebug.so(+0x15e3a) [0x7efcd7064e3a]
?18  0x5612e5b6007c in php8.0(+0x10a07c) [0x5612e5b6007c]
#19  0x5612e5d7fd89 in execute_ex at php8.0
?20  0x7efcd7064e3a in /usr/lib/php/20200930/xdebug.so(+0x15e3a) [0x7efcd7064e3a]
?21  0x5612e5b6007c in php8.0(+0x10a07c) [0x5612e5b6007c]
#22  0x5612e5d7fd89 in execute_ex at php8.0
?23  0x7efcd7064e3a in /usr/lib/php/20200930/xdebug.so(+0x15e3a) [0x7efcd7064e3a]
?24  0x5612e5b6007c in php8.0(+0x10a07c) [0x5612e5b6007c]
#25  0x5612e5d7fd89 in execute_ex at php8.0
?26  0x7efcd7064e3a in /usr/lib/php/20200930/xdebug.so(+0x15e3a) [0x7efcd7064e3a]
#27  0x5612e5d800fc in zend_execute at php8.0
#28  0x5612e5d16b6d in zend_execute_scripts at php8.0
#29  0x5612e5cb361b in php_execute_script at php8.0
?30  0x5612e5da5dce in php8.0(+0x34fdce) [0x5612e5da5dce]
?31  0x5612e5b69aeb in php8.0(+0x113aeb) [0x5612e5b69aeb]
#32  0x7efcd960f09b in __libc_start_main at /lib/x86_64-linux-gnu/libc.so.6
#33  0x5612e5b69c4a in _start at php8.0

When does "Unable to add worker function" trigger?

Hi, we moved our workers into a dockerized autoscaled environment, but we started seeing this error: "Unable to add worker function".

Our setup: X gearman servers, Y gearman workers that listen on each server.

If we were to publish 400 messages, this error occurs for the last 10% of our messages.

Gearadmin query question

Hello,
I have a question regarding the behavior of Gearadmin.

Background
I am running Gearman on an AWS instance (ie. Instance A) with the private ip 10.0.3.1

Observation
I have noticed that Gearadmin will only return errors when performing a status query without the localhost ip of 127.0.0.1

ie.
gearadmin -h 127.0.0.1 -p 4730 --status
reverse 0 0 1

ie.
gearadmin -h 10.0.3.1 -p 4730 --status
Error: Error connecting to 10.0.3.1.

Why does this happen?

Adding Gearman server with host and port

Hello,

Background:
I am using Gearman with PHP and am having difficulty successfully adding Gearman clients with ports other than default. Documentation [ here ] suggests the following:
ie.
`<?php

// Create our client object.
$gmclient= new GearmanClient();

// Add two job servers, the first on the default 4730 port
$gmclient->addServer("10.0.0.1");
$gmclient->addServer("10.0.0.2", 7003);

?>`

Observation:
I am using two AWS instances as a testing environment. I have confirmed with AWS that the instances are connecting. I can successfully add a server in the default configuration or by specifying the localhost ip.
ie.
`<?php

// Create our client object.
$gmclient= new GearmanClient();

// Add two job servers, the first on the default 4730 port
$gmclient->addServer("127.0.0.1");
$gmclient->addServer("127.0.0.1", 4730); // note port update

?>`

However I cannot successfully add a server when departing from the the default host value.
ie.
`<?php

// Create our client object.
$gmclient= new GearmanClient();

// Add two job servers, the first on the default 4730 port
$gmclient->addServer("10.0.3.1");
$gmclient->addServer("10.0.3.1", 4730); // note port update

?>`

Php error:
Fatal error: Uncaught GearmanException: Failed to set exception option in /var/www/html/gearman_test.php:7 Stack trace: #0 /var/www/html/gearman_test.php.php(7): GearmanClient->addServer() #1 {main} thrown in /var/www/html/gearman_test.php.php on line 7

Machine Observations:
2x Fresh AWS Ubuntu 24 instances running PHP 8.3 and Apache.
No VPC security group rules are blocking communications.
No firewalls are enabled.
No iptables are enabled.
And the following listener is enabled on each machine:
ie.
sudo netstat -tulpn | grep LISTEN
tcp 0 0 127.0.0.1:4730 0.0.0.0:* LISTEN 775/gearmand

Question:
At this point I am unsure if the underlying problem is a bug, a Gearman configuration issue, or a documentation issue. I am a new Gearman user. I think Gearman is the solution I am looking for however I do need help resolving this issue because my application really must leverage Gearman servers beyond localhost.

Please assist and many sincere thanks in advance.

GearmanWorker throws "GearmanException: Failed to set exception option" on addServer

Hello,

In the previous repository, there was an issue around addServer making connections for \GearmanClient which was resolved with a new 3rd parameter. (See wcgallego/pecl-gearman#59)

Is there any plan to also support this for addServer() and addServers() for the \GearmanWorker class as well? I was able to migrate my code to use the 3rd parameter for \GearmanClient and avoided the GearmanException: Failed to set exception option for that case.

However, for \GearmanWorker I'm still getting an error.

PHP Fatal error:  Uncaught GearmanException: Failed to set exception option in Gearman.php:33                                                                  
Stack trace:                                                                              
#0 /home/dev/app/Util/Gearman.php(33): GearmanWorker->addServer('127.0.0.1', 4730)

And trying to add the 3rd parameter (set to false), I am getting:

Warning: GearmanWorker::addServer() expects at most 2 parameters, 3 given in /home/dev/app/Util/Gearman.php on line 33

gearman extension version => 2.1.0
libgearman version => 1.1.19.1

Thanks for any input!

Jobs are no longer retried if PHP exits with a non-zero value

As recently as version 2.0.6, (with PHP 7.4, libgearman 1.1.12) if PHP exited with a non-zero value while a worker was working on a job, the job would be returned to the stack, and would be retried as soon as it started up again. We recently upgraded to PHP 8, libgearman 1.1.19.1 and 2.1.2 of the Gearman extension, and it seems as if this is no longer the case; now if a PHP process crashes in the middle of a job, it seems that the job is essentially lost--it does not go back on the queue. If this is a change in the behavior, was it intentional?

The (old) behavior is discussed here:
https://stackoverflow.com/questions/8870132/error-conditions-and-retries-in-gearman/10348461#10348461
and here:
https://stackoverflow.com/questions/15790531/delay-a-gearman-job-in-php

PHP 8.2 support

In a few days PHP 8.2 will be released, is it possible to get the extension to support PHP 8.2?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.