hjr3 / pecl-gearman Goto Github PK
View Code? Open in Web Editor NEWPHP wrapper to libgearman
License: Other
PHP wrapper to libgearman
License: Other
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 The Gearman PHP Extension requires the Gearman C server and library package to be installed. You can download the latest from: https://launchpad.net/gearmand/+download 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 seperate 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
Hi, I have a small problem with libgearman version => 1.1.12
(for libgearman version => 1.1.8 - all working fine)
I try to "$worker->addFunction()" after "$worker->unregisterAll()" and new function does not registered.
$worker->addServer('localhost', '4730');
//add test function
$worker->addFunction('test', 'test_function');
//unregister all
$worker->unregisterAll();
//try to add function
$worker->addFunction('test', 'test_function'); //- as result function no added
Hi
Is there any plan for this?
Thanks
Oli
$client = new \GearmanClient();
$client->context();
Segmentation fault (core dumped)
$ php -v
PHP 7.0.4-7ubuntu2.1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
<?php var_dump(phpversion('gearman'));
// "2.0.0-dev"
code:
$gmWorker = new GearmanWorker();
$gmWorker->setId("myid");
$gmWorker->addServers('192.168.1.2,192.168.1.3');
$gmWorker->addFunction('test', function() {
//...
});
while (@$gmWorker->work()) {
if ($gmWorker->returnCode() !== GEARMAN_SUCCESS) {
break;
}
}
bugs:
PHP Api Version: 20151012
Zend Module Api No: 20151012
Zend Extension Api No: 320151012
/home/u/pecl-gearman-master/php_gearman.c:3640:13: warning: ‘gearman_client_obj_free’ defined but not used [-Wunused-function]
/home/u/pecl-gearman-master/php_gearman.c:3720:13: warning: ‘gearman_worker_obj_free’ defined but not used [-Wunused-function]
/home/u/pecl-gearman-master/php_gearman.c:3785:13: warning: ‘gearman_job_obj_free’ defined but not used [-Wunused-function]
/home/u/pecl-gearman-master/php_gearman.c:3850:13: warning: ‘gearman_task_obj_free’ defined but not used [-Wunused-function]
make: *** [php_gearman.lo] Fehler 1
any idea?
Step to reproduce:
gearmand --listen 127.0.0.1
php examples/reverse_worker.php
php examples/reverse_client.php
Expected: Reversed string in the stdout
Result: No output in stdout.
Error message in log:
"ERROR 2016-11-08 13:43:18.000000 [ main ] Timeout occured when calling bind() for
0.0.0.0:4730 -> libgearman-server/gearmand.cc:679"
netbeans or other
/tmp/pecl-gearman/php_gearman.c:4859: error: âGEARMAN_WORKER_ALLOCATEDâ undeclared (first use in this function)
/tmp/pecl-gearman/php_gearman.c:4862: error: âGEARMAN_WORKER_NON_BLOCKINGâ undeclared (first use in this function)
/tmp/pecl-gearman/php_gearman.c:4865: error: âGEARMAN_WORKER_PACKET_INITâ undeclared (first use in this function)
/tmp/pecl-gearman/php_gearman.c:4868: error: âGEARMAN_WORKER_GRAB_JOB_IN_USEâ undeclared (first use in this function)
/tmp/pecl-gearman/php_gearman.c:4871: error: âGEARMAN_WORKER_PRE_SLEEP_IN_USEâ undeclared (first use in this function)
/tmp/pecl-gearman/php_gearman.c:4874: error: âGEARMAN_WORKER_WORK_JOB_IN_USEâ undeclared (first use in this function)
/tmp/pecl-gearman/php_gearman.c:4877: error: âGEARMAN_WORKER_CHANGEâ undeclared (first use in this function)
/tmp/pecl-gearman/php_gearman.c:4880: error: âGEARMAN_WORKER_GRAB_UNIQâ undeclared (first use in this function)
/tmp/pecl-gearman/php_gearman.c:4883: error: âGEARMAN_WORKER_TIMEOUT_RETURNâ undeclared (first use in this function)
/tmp/pecl-gearman/php_gearman.c:4886: error: âGEARMAN_WORKER_STATE_STARTâ undeclared (first use in this function)
/tmp/pecl-gearman/php_gearman.c:4889: error: âGEARMAN_WORKER_STATE_FUNCTION_SENDâ undeclared (first use in this function)
/tmp/pecl-gearman/php_gearman.c:4892: error: âGEARMAN_WORKER_STATE_CONNECTâ undeclared (first use in this function)
/tmp/pecl-gearman/php_gearman.c:4895: error: âGEARMAN_WORKER_STATE_GRAB_JOB_SENDâ undeclared (first use in this function)
/tmp/pecl-gearman/php_gearman.c:4898: error: âGEARMAN_WORKER_STATE_GRAB_JOB_RECVâ undeclared (first use in this function)
/tmp/pecl-gearman/php_gearman.c:4901: error: âGEARMAN_WORKER_STATE_PRE_SLEEPâ undeclared (first use in this function)
/tmp/pecl-gearman/php_gearman.c: In function âzm_info_gearmanâ:
/tmp/pecl-gearman/php_gearman.c:4921: error: âGEARMAN_DEFAULT_TCP_PORTâ undeclared (first use in this function)
i got a memory leak while i use php7.0.17 debug version , gearman 1.0.2 and valgrind to check memory leak.
PHP code is :
$client = new GearmanClient();
$gearmanIp = "10.222.332.123";
$gearmanPort = 4730;
$client->addServer($gearmanIp, $gearmanPort);
$parameter = 'test';
$gearman_result = $client->doNormal("getList", $parameter);
$result = json_decode($gearman_result, true);
var_dump($result);
debug php7.0.17 shows:
php_gearman.c(892) : Freeing 0x7F81E8C7A000 (687 bytes).
valgrind shows:
==24899== HEAP SUMMARY:
==24899== in use at exit: 18,808 bytes in 59 blocks
==24899== total heap usage: 24,413 allocs, 24,354 frees, 3,061,989 bytes allocated
==24899==
==24899== 687 bytes in 1 blocks are definitely lost in loss record 30 of 34
==24899== at 0x4C2817A: malloc (vg_replace_malloc.c:298)
==24899== by 0xA1934A: __zend_malloc (zend_alloc.c:2864)
==24899== by 0xA18584: _emalloc (zend_alloc.c:2457)
==24899== by 0xF789719: _php_malloc (php_gearman.c:892)
==24899== by 0xF9A5BFC: _client_do(gearman_client_st*, gearman_command_t, char const*, char const*, void const*, unsigned long, unsigned long*, gearman_return_t*) (client.cc:185)
==24899== by 0xF9A5DB7: gearman_client_do (client.cc:617)
==24899== by 0xF78CC48: gearman_client_do_work_handler (php_gearman_client.c:374)
==24899== by 0xF78CDCB: zif_gearman_client_do_normal (php_gearman_client.c:401)
==24899== by 0xAABF7F: ZEND_DO_FCALL_SPEC_HANDLER (zend_vm_execute.h:842)
==24899== by 0xAAAD78: execute_ex (zend_vm_execute.h:417)
==24899== by 0xAAAEA2: zend_execute (zend_vm_execute.h:458)
==24899== by 0xA4DDDE: zend_execute_scripts (zend.c:1443)
==24899==
==24899== LEAK SUMMARY:
==24899== definitely lost: 687 bytes in 1 blocks
==24899== indirectly lost: 0 bytes in 0 blocks
==24899== possibly lost: 0 bytes in 0 blocks
==24899== still reachable: 18,121 bytes in 58 blocks
==24899== suppressed: 0 bytes in 0 blocks
==24899== Reachable blocks (those to which a pointer was found) are not shown.
==24899== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==24899==
==24899== For counts of detected and suppressed errors, rerun with: -v
==24899== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)
I'm compiling PHP 5.6.3 from git with thread-safe support (--enable-maintainer-zts
) along with this extension (also from git) and during the process, the compilation returns an error:
/tmp/php-src/ext/gearman/php_gearman.c: In function ‘_php_task_cb_fn’:
/tmp/php-src/ext/gearman/php_gearman.c:2633:3: error: too few arguments to function ‘zend_objects_store_add_ref_by_handle’
zend_objects_store_add_ref_by_handle(task->value.handle);
^
In file included from /tmp/php-src/Zend/zend_globals.h:35:0,
from /tmp/php-src/Zend/zend_compile.h:431,
from /tmp/php-src/Zend/zend_modules.h:26,
from /tmp/php-src/Zend/zend_API.h:26,
from /tmp/php-src/main/php.h:39,
from /tmp/php-src/ext/gearman/php_gearman.c:16:
/tmp/php-src/Zend/zend_objects_API.h:70:15: note: declared here
ZEND_API void zend_objects_store_add_ref_by_handle(zend_object_handle handle TSRMLS_DC);
^
/tmp/php-src/ext/gearman/php_gearman.c:2670:3: error: too few arguments to function ‘zend_objects_store_del_ref_by_handle’
zend_objects_store_del_ref_by_handle(task->value.handle);
^
In file included from /tmp/php-src/Zend/zend_globals.h:35:0,
from /tmp/php-src/Zend/zend_compile.h:431,
from /tmp/php-src/Zend/zend_modules.h:26,
from /tmp/php-src/Zend/zend_API.h:26,
from /tmp/php-src/main/php.h:39,
from /tmp/php-src/ext/gearman/php_gearman.c:16:
/tmp/php-src/Zend/zend_objects_API.h:72:32: note: declared here
static zend_always_inline void zend_objects_store_del_ref_by_handle(zend_object_handle handle TSRMLS_DC) {
^
make: *** [ext/gearman/php_gearman.lo] Error 1
I've fixed this by changing line 2633 from:
zend_objects_store_add_ref_by_handle(task->value.handle);
to:
zend_objects_store_add_ref_by_handle(task->value.handle TSRMLS_CC);
and line 2670 from:
zend_objects_store_del_ref_by_handle(task->value.handle);
to:
zend_objects_store_del_ref_by_handle(task->value.handle TSRMLS_CC);
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.