Giter Site home page Giter Site logo

php-zmq's Introduction

PHP bindings for 0MQ. The documentation is available at http://php.net/zmq

Build Status

The API is roughly as follows:

<?php

/* Create new queue object */
$queue = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_REQ, "MySock1");

/* Connect to an endpoint */
$queue->connect("tcp://127.0.0.1:5555");

/* send and receive */
var_dump($queue->send("hello there, using socket 1")->recv());

?>

For installation instructions see http://pecl.php.net/zmq

For developer instructions see DEVELOPERS.md

php-zmq's People

Contributors

alexat avatar bluca avatar drhayt avatar gplanchat avatar h4cc avatar ianbarber avatar incognito avatar indeyets avatar mkoppanen avatar orvid avatar phuedx avatar ralphbean avatar remicollet avatar wangxx2026 avatar wysman avatar zebastian 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  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  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  avatar

Watchers

 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-zmq's Issues

Compilation fails with undeclared types

I can compile 0.6.0 just fine, so I can start using php-zmq, I would like to use the latest version though.
First the basics:

$ pkg-config --modversion libzmq
2.1.10
$ php -v
PHP 5.3.8 with Suhosin-Patch (cli) (built: Sep 30 2011 05:34:36) 
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

The ./configure works just fine, However:

$ make
/bin/sh /home/sid/Downloads/php-zmq/libtool --mode=compile cc  -I. -I/home/sid/Downloads/php-zmq -DPHP_ATOM_INC -I/home/sid/Downloads/php-zmq/include -I/home/sid/Downloads/php-zmq/main -I/home/sid/Downloads/php-zmq -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /home/sid/Downloads/php-zmq/zmq.c -o zmq.lo 
mkdir .libs
cc -I. -I/home/sid/Downloads/php-zmq -DPHP_ATOM_INC -I/home/sid/Downloads/php-zmq/include -I/home/sid/Downloads/php-zmq/main -I/home/sid/Downloads/php-zmq -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/sid/Downloads/php-zmq/zmq.c  -fPIC -DPIC -o .libs/zmq.o
/home/sid/Downloads/php-zmq/zmq.c: In function ‘zim_zmqsocket_getsockettype’:
/home/sid/Downloads/php-zmq/zmq.c:883:47: error: ‘ZMQ_TYPE’ undeclared (first use in this function)
/home/sid/Downloads/php-zmq/zmq.c:883:47: note: each undeclared identifier is reported only once for each function it appears in
/home/sid/Downloads/php-zmq/zmq.c: In function ‘zm_startup_zmq’:
/home/sid/Downloads/php-zmq/zmq.c:1697:2: error: ‘ZMQ_DEALER’ undeclared (first use in this function)
/home/sid/Downloads/php-zmq/zmq.c:1698:2: error: ‘ZMQ_ROUTER’ undeclared (first use in this function)
make: *** [zmq.lo] Error 1

This is the phpize and ./configure output, in case it's needed.

$ phpize 
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
configure.in:3: warning: prefer named diversions
configure.in:3: warning: prefer named diversions

$ ./configure 
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
checking for PHP extension directory... /usr/lib/php/modules
checking for PHP installed headers prefix... /usr/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether to enable 0MQ support... yes, shared
checking for pkg-config... /usr/bin/pkg-config
checking libzmq installation... found version 2.1.10, under /usr
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for stdint.h... (cached) yes
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h

FreeBSD segfault

Environment: FreeBSD 6.1, php-cli 5.3.3, 0mq 2.1

Scripts work but on termination, php-cli segfaults.

Smallest test case:


Backtrace from gdb:

#0  0x282a3a98 in r_debug_state () from /libexec/ld-elf.so.1
#1  0x282a6a0e in dlclose () from /libexec/ld-elf.so.1
#2  0x0818e634 in zend_hash_apply_deleter ()
#3  0x0818e6cf in zend_hash_graceful_reverse_destroy ()
#4  0x0818303c in zend_shutdown ()
#5  0x0813be82 in php_module_shutdown ()
#6  0x081fd9ad in main ()

I commented out everything in extensions.ini (except for extensions=zmq.so), so it's quite minimal:

PHP 5.3.3 with Suhosin-Patch (cli) (built: Nov 19 2010 19:21:46)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

<?php $x = get_loaded_extensions(); sort($x); var_dump(implode("\n", $x));
string(69) "Core
Reflection
SPL
date
ereg
libxml
mysqlnd
pcre
standard
xdebug
zmq"

Unable to initialize zmq module(Windows, PHP 5.3.1)

Get the following warning on PHP initialization:

PHP Warning: PHP Startup: zmq: Unable to initialize module
Module compiled with build ID=API20090626,TS,VC9
PHP compiled with build ID=API20090626,TS,VC6

Windows XP SP3, PHP 5.3.1, php_zmq_ts.dll.

Thanks in advance for any help.

Undefined class constant 'SOCKOPT_LINGER'

Running the Lazy Pirate example ( http://zguide.zeromq.org/php:lpclient ) gives the error Undefined class constant 'SOCKOPT_LINGER' when trying to do $client->setSockOpt(ZMQ::SOCKOPT_LINGER, 0);

zmq installed via the pear channel as per instructions here: http://www.zeromq.org/bindings:php and is at version 0.8.0

$ php -v
PHP 5.3.5-1ubuntu7.2 with Suhosin-Patch (cli) (built: May 2 2011 23:00:17)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

package.xml missing pollset entries

The package.xml is missing the zmq_pollset.c and php_zmq_pollset.h file entries. Here is a patch:

index 76ccadb..192c210 100644
--- a/package.xml
+++ b/package.xml
@@ -35,9 +35,11 @@
     <tasks:replace from="@PACKAGE_VERSION@" to="version" type="package-info" />
    </file>
    <file name="php_zmq_private.h" role="src" />
+   <file name="php_zmq_pollset.h" role="src" />

    <!-- Source files -->
    <file name="zmq.c" role="src" />
+   <file name="zmq_pollset.c" role="src" />

    <!-- misc files -->
    <file name="README" role="doc" />

bind dsn failed

Hi, i tried the simple-server.php :

try {
$server = new ZMQ(ZMQ::SOCKET_REP);
$server->bind("tcp://127.0.0.1:5555", true);
} catch (Exception $e) {
echo $e->getMessage();
}

/* Loop receiving and echoing back /
while ($message = $server->recv()) {
echo "Got message: $message\n";
/
echo back the message */
$server->send($message);
}

but found i could not got any response or backtrace after call "$server->bind(...)" method. My php version is PHP 5.2.12.

php bindings on zmq beta 3.1.0 fail to build

The last command in the documentation results in a failure on make for the latest beta version:

...
/tmp/pear/temp/zmq.c: In function 'zm_startup_zmq':
/tmp/pear/temp/zmq.c:1705:2: error: 'ZMQ_SNDLABEL' undeclared (first use in this function)
...
make: *** [zmq.lo] Error 1
ERROR: `make' failed

(Please note this information was typed in here as it is on a VM from which I don't appear to be able to copy/paste between it and the host server. I believe it to be devoid of typos!)

Problem with loading php_zmq_ts.dll extension

I downloaded the php_zmq_ts.dll extension from http://valokuva.org/builds/ and when i tried to load the extension i get the following error in php_error_log "Unable to load dynamic library 'c:/wamp/bin/php/php5.2.9-2/ext/php_zmq_ts.dll' - The specified procedure could not be found.". Please what could be the issue. I'm running a Windows 7 64-bit. Is the extension dependent on the system type? If so can I get working extensions for both 32-bit and 64-bit? Thanks

FreeBSD hangs after issuing new ZMSocket()

Hello!

We are integrating ZMQ/PHP into pfSense. We created a FreeBSD port for PHP-ZMQ here: http://redmine.pfsense.org/projects/pfsense-tools/repository/revisions/master/show/pfPorts/php-zmq

After working around FreeBSD threading issues and such we have the PHP module loading without errors.

The problem is when issuing a ZMSocket() call FreeBSD hangs and I show it in a state of umtxn.

Further inspection shows this from proctstat:

PID TID COMM TDNAME KSTACK
55953 64138 php initial thread mi_switch sleepq_type sleepq_type sleepq_wait_sig _sleep _umtx_lock _umtx_lock _umtx_lock _umtx_op syscall Xint0x80_syscall

So it appears that something is locked and the ZMQSocket call never returns. Do you guys have any ideas or anything that might help me troubleshoot this issue?

Thanks in advance!

0MQ version 3.2.2 stable

Hello,

Will the latest tag 1.0.3 work with 0MQ version 3.2.2 stable released on 2012/11/23?
NOTE: I see that there is a branch called zeromq3-prep.

Can't use ipc from apache (Pipeline)

Very simple script. (NOTE, the function getRandomString just creates a random string, its not important)

The sender.php:

<?php

function getRandomString($valid_chars, $length) {
     // start with an empty random string
    $random_string = "";

    // count the number of chars in the valid chars string so we know how many choices we have
    $num_valid_chars = strlen($valid_chars);

    // repeat the steps until we've created a string of the right length
    for ($i = 0; $i < $length; $i++) {
         // pick a random number from 1 up to the number of valid chars
         $random_pick = mt_rand(1, $num_valid_chars);

        // take the random character out of the string of valid chars
        // subtract 1 from $random_pick because strings are indexed starting at 0, and we started picking at 1
        $random_char = $valid_chars[$random_pick-1];

        // add the randomly-chosen char onto the end of our string so far
        $random_string .= $random_char;
    }

    // return our finished random string
    return $random_string;
}

$type = ZMQ::SOCKET_PUSH;
$p1 = ($_SERVER['argv'])?'cli':'web').'->'.getRandomString(isset($_SERVER['argv'])?'cli':'web'), 25);
$p2 = getRandomString('qwertyuiopasdfghjklzxcvbnm,1234567890', 500);
$context = new ZMQContext();
$socket = new ZMQSocket($context, $type)
$socket->connect(ipc://mytest.ipc);

$success = $socket->send($p1, ZMQ::MODE_SNDMORE);
$success &= $socket->send('', ZMQ::MODE_SNDMORE);
$success &= $socket->send($p2);

echo $success ? 'YAY  :)' : 'FAIL :(';

receiver.php

<?php
$type = ZMQ::SOCKET_PUSH;
$context = new ZMQContext();
$socket = new ZMQSocket($context, $type)
$socket->bind(ipc://mytest.ipc);
while(true){
    echo $socket->recv();
    echo $socket->recv();
    echo '->msg('.strlen($socket->recv()).')';
}

How to test.

run the receiver.php on the console.

run the sender.php on the console (you will see "YAY")
look at the receiver and it will have: "cli->lciciclciclliclccilcilcil(500)"

open the sender using apache (you will see "YAY" on the browser)
look at the receiver and it will have: "cli->lciciclciclliclccilcilcil(500)" //NOTHING WILL BE RECEIVED
^^^^ERROR^^^^

modify the scripts to use tcp (bind to tcp://*:5555 and connect to tcp://localhost:5555)

(repeat test)

run the receiver.php on the console.

run the sender.php on the console (you will see "YAY")
look at the receiver and it will have: "cli->lciciclciclliclccilcilcil(500)"

open the sender using apache (you will see "YAY" on the browser)
look at the receiver and it will have: "web->wbeebwbebwbebbewbbwewebwb(500)"

PHP binding not up to date with latest zmq 2.2.0?

Reading the zmq docs for 2.2.0 I find that they have added zmq_term (http://api.zeromq.org/2-2:zmq-term) which addresses some shutdown issues I have with running zmq as daemons. However, I cannot find reference to it in the PHP docs or the api.php file here in github. Is the PHP binding up to date with ZMQ 2.2.0 release? If not, is there an ETA as to when it will be? Many thanks.

SOCKOPT_RCVTIMEO and SOCKOPT_SENDTIMEO should be allowed for zmq 2.2

ZeroMQ 2.2 supports the options SOCKOPT_RCVTIMEO and SOCKOPT_SENDTIMEO. zmq_sockopt.c should be updated to reflect this.

see patch below:

--- zmq_sockopt.c.old 2012-06-27 17:09:51.873279868 -0400
+++ zmq_sockopt.c 2012-06-27 17:12:12.845281036 -0400
@@ -678,6 +678,683 @@

#endif

+#if ZMQ_VERSION_MAJOR == 2 & ZMQ_VERSION_MINOR == 2
+
+/* {{{ proto mixed ZMQSocket::getSockOpt()

  • Get a socket option
    +*/
    +PHP_METHOD(zmqsocket, getsockopt)
    +{
  • php_zmq_socket_object *intern;
  • long key;
  • size_t value_len;
  • if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &key) == FAILURE) {
  •   return;
    
  • }
  • intern = PHP_ZMQ_SOCKET_OBJECT;
  • if (!intern->socket) {
  •   zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "The socket has not been initialized yet", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •   return;
    
  • }
  • switch (key) {
  •   case ZMQ_HWM:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_HWM value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SWAP:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_SWAP value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_AFFINITY:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_AFFINITY value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RATE:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RATE value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECOVERY_IVL value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL_MSEC:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECOVERY_IVL_MSEC value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_MCAST_LOOP:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_MCAST_LOOP value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SNDBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_SNDBUF value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       value_len = sizeof(uint64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RCVBUF value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_LINGER:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_LINGER value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECONNECT_IVL value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL_MAX:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RECONNECT_IVL_MAX value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_BACKLOG:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_BACKLOG value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SUBSCRIBE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_SUBSCRIBE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   case ZMQ_UNSUBSCRIBE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Getting ZMQ::SOCKOPT_UNSUBSCRIBE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   case ZMQ_TYPE:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_TYPE value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVMORE:
    
  •   {
    
  •       int64_t value;
    
  •       value_len = sizeof(int64_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RCVMORE value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_EVENTS:
    
  •   {
    
  •       uint32_t value;
    
  •       value_len = sizeof(uint32_t);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_EVENTS value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_SNDTIMEO:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_SNDTIMEO value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVTIMEO:
    
  •   {
    
  •       int value;
    
  •       value_len = sizeof(int);
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, &value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_RCVTIMEO value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_LONG(value);
    
  •   }
    
  •   break;
    
  •   case ZMQ_FD:
    
  •   {
    
  •       php_stream *stm = php_zmq_create_zmq_fd(getThis() TSRMLS_CC);
    
  •       if (stm) {
    
  •           php_stream_to_zval(stm, return_value);
    
  •           return;
    
  •       }
    
  •       RETURN_FALSE;
    
  •   }
    
  •   break;
    
  •   case ZMQ_IDENTITY:
    
  •   {
    
  •       unsigned char value[PHP_ZMQ_IDENTITY_LEN];
    
  •       value_len = PHP_ZMQ_IDENTITY_LEN;
    
  •       if (zmq_getsockopt(intern->socket->z_socket, (int) key, value, &value_len) != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to get the option ZMQ::SOCKOPT_IDENTITY value: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •       RETURN_STRINGL((char *) value, value_len, 1);
    
  •   }
    
  •   break;
    
  •   default:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Unknown option key", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  • }
    +}
    +/* {{{ proto ZMQSocket ZMQSocket::setSockOpt(integer $SOCKOPT, mixed $value)
  • Set a socket option
    +*/
    +PHP_METHOD(zmqsocket, setsockopt)
    +{
  • php_zmq_socket_object *intern;
  • long key;
  • zval *pz_value;
  • int status;
  • if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz/", &key, &pz_value) == FAILURE) {
  •   return;
    
  • }
  • intern = PHP_ZMQ_SOCKET_OBJECT;
  • if (!intern->socket) {
  •   zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "The socket has not been initialized yet", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •   return;
    
  • }
  • switch (key) {
  •   case ZMQ_HWM:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_HWM option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_SWAP:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_SWAP option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_AFFINITY:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_AFFINITY option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_IDENTITY:
    
  •   {
    
  •       convert_to_string(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, Z_STRVAL_P(pz_value), Z_STRLEN_P(pz_value));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_IDENTITY option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;  
    
  •   case ZMQ_RATE:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RATE option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECOVERY_IVL option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECOVERY_IVL_MSEC:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECOVERY_IVL_MSEC option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_MCAST_LOOP:
    
  •   {
    
  •       int64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_MCAST_LOOP option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_SNDBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_SNDBUF option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVBUF:
    
  •   {
    
  •       uint64_t value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (uint64_t) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(uint64_t));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RCVBUF option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_LINGER:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_LINGER option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECONNECT_IVL option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_RECONNECT_IVL_MAX:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_RECONNECT_IVL_MAX option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_BACKLOG:
    
  •   {
    
  •       int value;
    
  •       convert_to_long(pz_value);
    
  •       value  = (int) Z_LVAL_P(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, &value, sizeof(int));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_BACKLOG option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;
    
  •   case ZMQ_SUBSCRIBE:
    
  •   {
    
  •       convert_to_string(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, Z_STRVAL_P(pz_value), Z_STRLEN_P(pz_value));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_SUBSCRIBE option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;  
    
  •   case ZMQ_UNSUBSCRIBE:
    
  •   {
    
  •       convert_to_string(pz_value);
    
  •       status = zmq_setsockopt(intern->socket->z_socket, key, Z_STRVAL_P(pz_value), Z_STRLEN_P(pz_value));
    
  •       if (status != 0) {
    
  •           zend_throw_exception_ex(php_zmq_socket_exception_sc_entry_get (), errno TSRMLS_CC, "Failed to set socket ZMQ::SOCKOPT_UNSUBSCRIBE option: %s", zmq_strerror(errno));
    
  •           return;
    
  •       }
    
  •   }
    
  •   break;  
    
  •   case ZMQ_TYPE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_TYPE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   case ZMQ_RCVMORE:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Setting ZMQ::SOCKOPT_RCVMORE is not supported", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  •   default:
    
  •   {
    
  •       zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "Unknown option key", PHP_ZMQ_INTERNAL_ERROR TSRMLS_CC);
    
  •       return;
    
  •   }
    
  •   break;
    
  • }
  • ZMQ_RETURN_THIS;
    +}

    +void php_zmq_register_sockopt_constants (zend_class_entry *php_zmq_sc_entry TSRMLS_DC)
    +{
    +#define PHP_ZMQ_REGISTER_SOCKOPT(const_name, value) \

  • zend_declare_class_constant_long(php_zmq_sc_entry, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_HWM", ZMQ_HWM);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SWAP", ZMQ_SWAP);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_AFFINITY", ZMQ_AFFINITY);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_IDENTITY", ZMQ_IDENTITY);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RATE", ZMQ_RATE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECOVERY_IVL", ZMQ_RECOVERY_IVL);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECOVERY_IVL_MSEC", ZMQ_RECOVERY_IVL_MSEC);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_MCAST_LOOP", ZMQ_MCAST_LOOP);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDBUF", ZMQ_SNDBUF);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVBUF", ZMQ_RCVBUF);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_LINGER", ZMQ_LINGER);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECONNECT_IVL", ZMQ_RECONNECT_IVL);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RECONNECT_IVL_MAX", ZMQ_RECONNECT_IVL_MAX);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_BACKLOG", ZMQ_BACKLOG);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SUBSCRIBE", ZMQ_SUBSCRIBE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_UNSUBSCRIBE", ZMQ_UNSUBSCRIBE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_TYPE", ZMQ_TYPE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVMORE", ZMQ_RCVMORE);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_FD", ZMQ_FD);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_EVENTS", ZMQ_EVENTS);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_SNDTIMEO", ZMQ_SNDTIMEO);

  • PHP_ZMQ_REGISTER_SOCKOPT("SOCKOPT_RCVTIMEO", ZMQ_RCVTIMEO);

  • +#undef PHP_ZMQ_REGISTER_SOCKOPT
    +}

  • +#endif
    +

    if ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 0

    /* {{{ proto mixed ZMQSocket::getSockOpt()

Please fix api.php

Hi there,

In api.php all the constants are defined in the ZMQSocket class, but they are actually in the ZMQ class.
If I try to use for example ZMQSocket::SOCKET_PUB I get a fatal error.
Also please add ZMQ::SOCKET_PULL there.

Unless this is needed for future changes this is broken since commit d44061f

Thanks for your work!

php_zmq_ts.dll from http://valokuva.org/builds/

I downloaded the dll from http://valokuva.org/builds/, when tried load the extension it says
'This application has failed to start because MSVCR90D.dll was not found. Re-installing the application may fix this problem.'
I read somewhere that if it requires MSVCR90D.dll it's because it's build on 'Debug' mode, will you rebuild on 'Release'

Segmentation fault: 11

------------------------------------php file-----------------------------------------


<?php
$context=new ZMQContext(1, false);
$server=new ZMQSocket($context, ZMQ::SOCKET_REP);
$server->bind('inproc://test');
$client=new ZMQSocket($context, ZMQ::SOCKET_REQ);
$client->connect('inproc://test');
$poll=new ZMQPoll();
$poll->add($server, ZMQ::POLL_IN);
$poll->add($client, ZMQ::POLL_IN);

for($i=0;$i<10;$i++)
{
    $readable = array();
    $writable = array();
    if($i%2)
    {
        $server->send($i);
    }
    else
    {
        $client->send($i);
    }
    $event=$poll->poll($readable, $writable);  
    if(!$event)
    {
        continue;
    }
    foreach ($readable as $socket)
    {
        $msg=$socket->recv();
        if($socket===$server)
        {
            echo 'client to server msg:'.$msg.PHP_EOL;
        }
        else
        {
            echo 'server to client msg:'.$msg.PHP_EOL;
        }
    }
}
?>

------------------------------------php file-----------------------------------------

------------------------------------php result-----------------------------------------
client to server msg:0
server to client msg:1
client to server msg:2
server to client msg:3
client to server msg:4
server to client msg:5
client to server msg:6
server to client msg:7
client to server msg:8
server to client msg:9
Segmentation fault: 11
------------------------------------php result-----------------------------------------

------------------------------------php info-----------------------------------------
PHP Version => 5.3.10

System => Darwin localhost 11.2.0 Darwin Kernel Version 11.2.0: Tue Aug 9 20:54:00 PDT 2011; root:xnu-1699.24.8~1/RELEASE_X86_64 x86_64
Build Date => Feb 10 2012 14:47:34
Configure Command => './configure' '--prefix=/usr' '--disable-all' '--enable-cli' '--with-curl' '--with-zmq' '--enable-json' '--enable-memcached' '--disable-memcached-session' '--disable-cgi' '--with-rune' '--disable-ipv6' '--with-zlib-dir=/opt/local'
Server API => Command Line Interface
------------------------------------php info-----------------------------------------

------------------------------------gdb bt-----------------------------------------
#0 0x0000000100181845 in zend_objects_store_del_ref_by_handle_ex (handle=6388696, handlers=0x1002f6ea0) at zend_objects_API.c:196
#1 0x0000000100181a5a in zend_objects_store_del_ref (zobject=0x100615ce8) at zend_objects_API.c:173
#2 0x000000010010ab78 in php_zmq_socket_object_free_storage (object=0x617bd8) at zmq.c:1470
#3 0x00000001001819a1 in zend_objects_store_del_ref_by_handle_ex (handle=6388696, handlers=0x1002f6ea0) at zend_objects_API.c:220
#4 0x0000000100181a5a in zend_objects_store_del_ref (zobject=0x100617c18) at zend_objects_API.c:173
#5 0x000000010015619a in _zval_dtor inlined at /Users/dark9/Downloads/php-5.3.10/Zend/zend_variables.h:35
#6 0x000000010015619a in _zval_ptr_dtor (zval_ptr=0x617bd8) at zend_variables.h:447
#7 0x000000010016d3d4 in zend_hash_apply_deleter (ht=0x1002e45c8, p=0x1006182b8) at zend_hash.c:612
#8 0x000000010016d608 in zend_hash_graceful_reverse_destroy (ht=0x617bd8) at zend_hash.c:647
#9 0x00000001001589fb in shutdown_executor () at zend_execute_API.c:256
#10 0x0000000100161f63 in zend_deactivate () at zend.c:891
#11 0x0000000100110539 in php_request_shutdown (dummy=0x617bd8) at main.c:1661
#12 0x00000001001dc653 in main (argc=1606417440, argv=0x7fff5fbffc20) at php_cli.c:1363

------------------------------------gdb bt-----------------------------------------

------------------------------------php-zmq info-----------------------------------------
mkoppanen-php-zmq-1.0.2-2-g2d1fb76.zip
------------------------------------php-zmq info-----------------------------------------

configure: error: Unable to find libzmq installation

Hi, when I'm trying to compile your package, I keep getting this error:

phpize && ./configure
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc and cc understand -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
checking for PHP extension directory... /usr/lib/php5/20060613+lfs
checking for PHP installed headers prefix... /usr/include/php5
checking for re2c... re2c
checking for re2c version... 0.13.5 (ok)
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking whether to enable ZeroMQ support... yes, shared
checking for pkg-config... no
checking libzmq installation... configure: error: Unable to find libzmq installation

I have followed the installation guide to 0mq from here: http://www.zeromq.org/area:download-v20 with make and # make install . /usr/local/lib/ contains libzmq.a, libzmq.la, libzmq.so, libzmq.so.0 and libzmq.so.0.0.0 . I have also tried to run # ldconfig .

Can you help me?

Build failure on Ubuntu 12.10

Hello,

when building on Ubuntu 12.10 with libzmq 3.2.2 some build errors occur. This happens for both the 1.0.4 tag as with the master branch.

build@Annabellog:~/zmq/php/php-zmq$ make
/bin/bash /home/build/zmq/php/php-zmq/libtool --mode=compile cc  -I. -I/home/build/zmq/php/php-zmq -DPHP_ATOM_INC -I/home/build/zmq/php/php-zmq/include -I/home/build/zmq/php/php-zmq/main -I/home/build/zmq/php/php-zmq -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/usr/local/include  -DHAVE_CONFIG_H  -g -O2   -c /home/build/zmq/php/php-zmq/zmq.c -o zmq.lo
libtool: compile:  cc -I. -I/home/build/zmq/php/php-zmq -DPHP_ATOM_INC -I/home/build/zmq/php/php-zmq/include -I/home/build/zmq/php/php-zmq/main -I/home/build/zmq/php/php-zmq -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /home/build/zmq/php/php-zmq/zmq.c  -fPIC -DPIC -o .libs/zmq.o
/bin/bash /home/build/zmq/php/php-zmq/libtool --mode=compile cc  -I. -I/home/build/zmq/php/php-zmq -DPHP_ATOM_INC -I/home/build/zmq/php/php-zmq/include -I/home/build/zmq/php/php-zmq/main -I/home/build/zmq/php/php-zmq -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/usr/local/include  -DHAVE_CONFIG_H  -g -O2   -c /home/build/zmq/php/php-zmq/zmq_pollset.c -o zmq_pollset.lo
libtool: compile:  cc -I. -I/home/build/zmq/php/php-zmq -DPHP_ATOM_INC -I/home/build/zmq/php/php-zmq/include -I/home/build/zmq/php/php-zmq/main -I/home/build/zmq/php/php-zmq -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /home/build/zmq/php/php-zmq/zmq_pollset.c  -fPIC -DPIC -o .libs/zmq_pollset.o
/bin/bash /home/build/zmq/php/php-zmq/libtool --mode=compile cc  -I. -I/home/build/zmq/php/php-zmq -DPHP_ATOM_INC -I/home/build/zmq/php/php-zmq/include -I/home/build/zmq/php/php-zmq/main -I/home/build/zmq/php/php-zmq -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/usr/local/include  -DHAVE_CONFIG_H  -g -O2   -c /home/build/zmq/php/php-zmq/zmq_device.c -o zmq_device.lo
libtool: compile:  cc -I. -I/home/build/zmq/php/php-zmq -DPHP_ATOM_INC -I/home/build/zmq/php/php-zmq/include -I/home/build/zmq/php/php-zmq/main -I/home/build/zmq/php/php-zmq -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /home/build/zmq/php/php-zmq/zmq_device.c  -fPIC -DPIC -o .libs/zmq_device.o
/bin/bash /home/build/zmq/php/php-zmq/libtool --mode=compile cc  -I. -I/home/build/zmq/php/php-zmq -DPHP_ATOM_INC -I/home/build/zmq/php/php-zmq/include -I/home/build/zmq/php/php-zmq/main -I/home/build/zmq/php/php-zmq -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/usr/local/include  -DHAVE_CONFIG_H  -g -O2   -c /home/build/zmq/php/php-zmq/zmq_sockopt.c -o zmq_sockopt.lo
libtool: compile:  cc -I. -I/home/build/zmq/php/php-zmq -DPHP_ATOM_INC -I/home/build/zmq/php/php-zmq/include -I/home/build/zmq/php/php-zmq/main -I/home/build/zmq/php/php-zmq -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /home/build/zmq/php/php-zmq/zmq_sockopt.c  -fPIC -DPIC -o .libs/zmq_sockopt.o
/home/build/zmq/php/php-zmq/zmq_sockopt.c: In function 'zim_zmqsocket_getsockopt':
/home/build/zmq/php/php-zmq/zmq_sockopt.c:3185:8: error: 'ZMQ_ROUTER_RAW' undeclared (first use in this function)
/home/build/zmq/php/php-zmq/zmq_sockopt.c:3185:8: note: each undeclared identifier is reported only once for each function it appears in
/home/build/zmq/php/php-zmq/zmq_sockopt.c: In function 'zim_zmqsocket_setsockopt':
/home/build/zmq/php/php-zmq/zmq_sockopt.c:3682:8: error: 'ZMQ_ROUTER_RAW' undeclared (first use in this function)
/home/build/zmq/php/php-zmq/zmq_sockopt.c: In function 'php_zmq_register_sockopt_constants':
/home/build/zmq/php/php-zmq/zmq_sockopt.c:3800:2: error: 'ZMQ_ROUTER_RAW' undeclared (first use in this function)
make: *** [zmq_sockopt.lo] Error 1

uname -a output:

Linux Annabellog 3.5.0-18-generic #29-Ubuntu SMP Fri Oct 19 10:26:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Segmentation fault on Mac OS X Snow Leopard

When trying the standard example of a queue device from the guid, the script exits with a segmentation fault. I installed the latest version of php-zmq with pecl install.

    $context = new \ZMQContext();

    //  Socket facing clients
    $frontend = $context->getSocket(\ZMQ::SOCKET_ROUTER);
    $frontend->bind("tcp://*:6666");

    //  Socket facing services
    $backend = $context->getSocket(\ZMQ::SOCKET_DEALER);
    $backend->bind("tcp://*:6665");

    //  Start built-in device
    $device = new \ZMQDevice(\ZMQ::DEVICE_QUEUE, $frontend, $backend);

This is the crash report:

  Process:         php [4705]
  Path:            /Applications/MAMP/bin/php/php5.3.6/bin/php
  Identifier:      php
  Version:         ??? (???)
  Code Type:       X86-64 (Native)
  Parent Process:  bash [4478]

  Date/Time:       2012-04-14 21:02:23.500 +0200
  OS Version:      Mac OS X 10.6.8 (10K549)
  Report Version:  6

  Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
  Exception Codes: KERN_INVALID_ADDRESS at 0x00000001fd925aa1
  Crashed Thread:  0  Dispatch queue: com.apple.main-thread

  Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
  0   php                               0x000000010039deec zend_objects_store_del_ref_by_handle_ex + 60
  1   php                               0x000000010039e16a zend_objects_store_del_ref + 26
  2   zmq.so                            0x0000000101797cbe php_zmq_device_object_free_storage + 78
  3   php                               0x000000010039e127 zend_objects_store_del_ref_by_handle_ex + 631
  4   php                               0x000000010039e16a zend_objects_store_del_ref + 26
  5   php                               0x000000010036df25 _zval_ptr_dtor + 149
  6   php                               0x000000010039ed9d zend_leave_helper_SPEC + 749
  7   php                               0x00000001003a2eab execute + 491
  8   php                               0x000000010037b40b zend_execute_scripts + 363
  9   php                               0x0000000100322df2 php_execute_script + 482
  10  php                               0x000000010040bc55 main + 5525
  11  php                               0x0000000100001164 start + 52

  Thread 1:
  0   libSystem.B.dylib                 0x00007fff81398c0a kevent + 10
  1   libzmq.1.dylib                    0x00000001039c525d zmq::kqueue_t::loop() + 159 (kqueue.cpp:166)
  2   libzmq.1.dylib                    0x00000001039d5189 thread_routine + 105 (thread.cpp:75)
  3   libSystem.B.dylib                 0x00007fff813b8fd6 _pthread_start + 331
  4   libSystem.B.dylib                 0x00007fff813b8e89 thread_start + 13

  Thread 2:
  0   libSystem.B.dylib                 0x00007fff81398c0a kevent + 10
  1   libzmq.1.dylib                    0x00000001039c525d zmq::kqueue_t::loop() + 159 (kqueue.cpp:166)
  2   libzmq.1.dylib                    0x00000001039d5189 thread_routine + 105 (thread.cpp:75)
  3   libSystem.B.dylib                 0x00007fff813b8fd6 _pthread_start + 331
  4   libSystem.B.dylib                 0x00007fff813b8e89 thread_start + 13

  Thread 0 crashed with X86 Thread State (64-bit):
    rax: 0x00000000fc59ee00  rbx: 0x0000000103f16828  rcx: 0x0000000101501ce0  rdx: 0x00000001fd925aa0
    rdi: 0x0000000003f167b8  rsi: 0x000000010179e1e0  rbp: 0x00007fff5fbfeb30  rsp: 0x00007fff5fbfea40
     r8: 0x00007fff5fbfec28   r9: 0x0000000103c55e20  r10: 0x0000000100c435ad  r11: 0x000000010039e150
    r12: 0x0000000103a1f188  r13: 0x0000000103a1f250  r14: 0x000000010411a480  r15: 0x0000000100c33420
    rip: 0x000000010039deec  rfl: 0x0000000000000206  cr2: 0x00000001fd925aa1

  Binary Images:
         0x100000000 -        0x100b0ffef +php ??? (???) <31571673-758A-3B9E-9100-2A48E0D7E3DE> /Applications/MAMP/bin/php/php5.3.6/bin/php
         0x100e30000 -        0x100e3eff7 +libexslt.0.dylib 9.15.0 (compatibility 9.0.0) <03DCAD7A-C88A-3781-8A34-48A25A4FF254> /Applications/MAMP/Library/lib/libexslt.0.dylib
         0x100e47000 -        0x100f3ffff +libiconv.2.dylib 8.0.0 (compatibility 8.0.0) <3D14216A-59BE-3EC8-990B-235AFCF364C6> /Applications/MAMP/Library/lib/libiconv.2.dylib
         0x100f5b000 -        0x100f94fe7 +libt1.5.dylib 7.2.0 (compatibility 7.0.0) <B9B8FB24-9933-3A34-B9A4-FB71D0C6857F> /Applications/MAMP/Library/lib/libt1.5.dylib
         0x100fc0000 -        0x101039fe7 +libfreetype.6.dylib 13.2.0 (compatibility 13.0.0) <B5A23779-FC52-3D8A-8968-E237B5C80F5D> /Applications/MAMP/Library/lib/libfreetype.6.dylib
         0x10106a000 -        0x10108cff7 +libpng15.15.dylib 16.0.0 (compatibility 16.0.0) <1E3945A6-EC5F-364D-9718-51B11B0860D4> /Applications/MAMP/Library/lib/libpng15.15.dylib
         0x10109d000 -        0x1010d2fe7 +libjpeg.8.dylib 12.0.0 (compatibility 12.0.0) <96E62140-0ECC-3E48-B4B2-0B7D30B16FC4> /Applications/MAMP/Library/lib/libjpeg.8.dylib
         0x1010e2000 -        0x10112cff7 +libcurl.4.dylib 7.0.0 (compatibility 7.0.0) <D55ABD06-7CDE-3BC0-90F2-85DFB35B7E8A> /Applications/MAMP/Library/lib/libcurl.4.dylib
         0x10113a000 -        0x10125cfff +libxml2.2.dylib 10.8.0 (compatibility 10.0.0) <1A2C04E2-3EBB-386C-BDF7-8BE3BF28BA0A> /Applications/MAMP/Library/lib/libxml2.2.dylib
         0x1012c7000 -        0x1012f5fef +libidn.11.dylib 18.0.0 (compatibility 18.0.0) <ADB35FA7-C0C1-3D5A-A64B-1A2B3AFB4CE8> /Applications/MAMP/Library/lib/libidn.11.dylib
         0x1012fc000 -        0x10132cff7 +libxslt.1.dylib 3.26.0 (compatibility 3.0.0) <8FA5ED66-8646-3433-A2A7-D3902AB760F9> /Applications/MAMP/Library/lib/libxslt.1.dylib
         0x10133f000 -        0x101348fef +libintl.8.dylib 10.1.0 (compatibility 10.0.0) <55EBD6B1-17FE-3772-A2EE-762E12BB0B2C> /Applications/MAMP/Library/lib/libintl.8.dylib
         0x1013c5000 -        0x1013d8fef +xcache.so ??? (???) <9011DCBF-2F3E-319C-B5D1-C90C2D08387F> /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/xcache.so
         0x1013e7000 -        0x1013eefff +yaz.so ??? (???) <9B21D358-6DA4-3501-B8CC-D79D994DF0D1> /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/yaz.so
         0x1013f4000 -        0x1013f5ff7 +gettext.so ??? (???) <04148C79-C321-3596-A19A-AD5E66407D2F> /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/gettext.so
         0x1013f8000 -        0x1013fbfef +pcntl.so ??? (???) <0972E369-4BD0-3B6A-9226-5C97F62FA7FE> /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/pcntl.so
         0x10154f000 -        0x10163bfef +imap.so ??? (???) <3C322B99-BAEA-3D0F-989B-D16457BBBE63> /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/imap.so
         0x101673000 -        0x101678fff +mcrypt.so ??? (???) <9BC3BE5E-01A9-3BF1-9BDF-64B323FCAC8F> /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so
         0x101680000 -        0x1016a5fff +libmcrypt.4.dylib 9.8.0 (compatibility 9.0.0) <174D3778-E9BC-318F-A5DE-92B257D482C0> /Applications/MAMP/Library/lib/libmcrypt.4.dylib
         0x1016c3000 -        0x1016c9ff7 +libltdl.7.dylib 11.0.0 (compatibility 11.0.0) <B9229DA5-940E-3FD3-8E21-92775AF7066D> /Applications/MAMP/Library/lib/libltdl.7.dylib
         0x1016d0000 -        0x1016e2ff7 +pgsql.so ??? (???) <44AB8EF0-F0D7-368B-A669-73120F01FB38> /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/pgsql.so
         0x1016f1000 -        0x10170cff7 +libpq.5.dylib 5.2.0 (compatibility 5.0.0) <DE5EB289-7BA9-3F9F-B91B-E2F4663C2865> /Applications/MAMP/Library/pg/lib/libpq.5.dylib
         0x101715000 -        0x10171afef +pdo_pgsql.so ??? (???) <AB4DED86-C321-3856-9227-1CEA60088A01> /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/pdo_pgsql.so
         0x101720000 -        0x10172bfe7 +gearman.so ??? (???) <E82C6FA9-0614-33E9-8EA3-F6A0ED4B483C> /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/gearman.so
         0x10173b000 -        0x101746ff7 +libgearman.4.dylib 5.0.0 (compatibility 5.0.0) <348E43C8-7DBC-3C04-8781-F5785F4F3B4C> /usr/local/lib/libgearman.4.dylib
         0x101750000 -        0x10176bfef +intl.so ??? (???) <85A874C8-203C-35D8-80C9-8C3012780A29> /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/intl.so
         0x101786000 -        0x10178eff7 +libicuio.48.dylib 48.1.0 (compatibility 48.0.0) <8FC07097-CCD2-268D-E70E-4D0D9A7009BD> /opt/local/lib/libicuio.48.dylib
         0x101794000 -        0x10179cff7 +zmq.so ??? (???) <1216B768-7627-3F38-A136-BE72257A6E44> /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/zmq.so
         0x102000000 -        0x102084fe7 +libyaz.4.dylib 5.0.0 (compatibility 5.0.0) <41E82684-D083-394E-991A-5D9681F607AA> /Applications/MAMP/Library/lib/libyaz.4.dylib
         0x1021a7000 -        0x1023e5ff7 +pdo_mysql.so ??? (???) <5F97F074-A41F-39CE-9998-0AED47542DA6> /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/pdo_mysql.so
         0x1024a2000 -        0x102635fe7 +libicui18n.48.dylib 48.1.0 (compatibility 48.0.0) <D4E48847-0BDA-95D3-554A-2133D36CD2B2> /opt/local/lib/libicui18n.48.dylib
         0x1026d2000 -        0x1027f5fef +libicuuc.48.dylib 48.1.0 (compatibility 48.0.0) <6B0F1B95-8CF2-CE38-91AA-E2830C68DC95> /opt/local/lib/libicuuc.48.dylib
         0x10284f000 -        0x1039bcff7 +libicudata.48.dylib 48.1.0 (compatibility 48.0.0) <2BCC1444-2439-CA6C-1A0D-CA83A2CB3436> /opt/local/lib/libicudata.48.dylib
         0x1039be000 -        0x1039edfff +libzmq.1.dylib 2.1.0 (compatibility 2.0.0) <19DC2D04-9099-3E16-B686-B8AEC97FA7C7> /usr/local/lib/libzmq.1.dylib
      0x7fff5fc00000 -     0x7fff5fc3be0f  dyld 132.1 (???) <29DECB19-0193-2575-D838-CF743F0400B2> /usr/lib/dyld
      0x7fff801ab000 -     0x7fff801bcff7  libz.1.dylib 1.2.3 (compatibility 1.0.0) <97019C74-161A-3488-41EC-A6CA8738418C> /usr/lib/libz.1.dylib
      0x7fff80f64000 -     0x7fff80fa1fff  com.apple.LDAPFramework 2.0 (120.1) <54A6769E-D7E2-DBE2-EA61-87B9EA355DA4> /System/Library/Frameworks/LDAP.framework/Versions/A/LDAP
      0x7fff811f1000 -     0x7fff812e9ff7  libiconv.2.dylib 7.0.0 (compatibility 7.0.0) <44AADE50-15BC-BC6B-BEF0-5029A30766AC> /usr/lib/libiconv.2.dylib
      0x7fff8137f000 -     0x7fff81540fef  libSystem.B.dylib 125.2.11 (compatibility 1.0.0) <9AB4F1D1-89DC-0E8A-DC8E-A4FE4D69DB69> /usr/lib/libSystem.B.dylib
      0x7fff818f0000 -     0x7fff819a0fff  edu.mit.Kerberos 6.5.11 (6.5.11) <085D80F5-C9DC-E252-C21B-03295E660C91> /System/Library/Frameworks/Kerberos.framework/Versions/A/Kerberos
      0x7fff81c25000 -     0x7fff81c2afff  libpam.2.dylib 3.0.0 (compatibility 3.0.0) <97F037FC-0CD8-D4B3-8133-7D7013791F86> /usr/lib/libpam.2.dylib
      0x7fff83a9b000 -     0x7fff83aa7fff  libbz2.1.0.dylib 1.0.5 (compatibility 1.0.0) <9AB864FA-9197-5D48-A0EC-EC8330D475FC> /usr/lib/libbz2.1.0.dylib
      0x7fff83b80000 -     0x7fff83b81ff7  com.apple.TrustEvaluationAgent 1.1 (1) <5952A9FA-BC2B-16EF-91A7-43902A5C07B6> /System/Library/PrivateFrameworks/TrustEvaluationAgent.framework/Versions/A/TrustEvaluationAgent
      0x7fff848e6000 -     0x7fff84963fef  libstdc++.6.dylib 7.9.0 (compatibility 7.0.0) <35ECA411-2C08-FD7D-11B1-1B7A04921A5C> /usr/lib/libstdc++.6.dylib
      0x7fff84964000 -     0x7fff849b0fff  libauto.dylib ??? (???) <F7221B46-DC4F-3153-CE61-7F52C8C293CF> /usr/lib/libauto.dylib
      0x7fff850ac000 -     0x7fff85336fe7  com.apple.security 6.1.2 (55002) <FD0B5AD4-74DB-7ED8-90D3-6EC56FFA8557> /System/Library/Frameworks/Security.framework/Versions/A/Security
      0x7fff8673b000 -     0x7fff8673fff7  libmathCommon.A.dylib 315.0.0 (compatibility 1.0.0) <95718673-FEEE-B6ED-B127-BCDBDB60D4E5> /usr/lib/system/libmathCommon.A.dylib
      0x7fff8696e000 -     0x7fff86980fe7  libsasl2.2.dylib 3.15.0 (compatibility 3.0.0) <76B83C8D-8EFE-4467-0F75-275648AFED97> /usr/lib/libsasl2.2.dylib
      0x7fff86e50000 -     0x7fff86fc7fe7  com.apple.CoreFoundation 6.6.6 (550.44) <BB4E5158-E47A-39D3-2561-96CB49FA82D4> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
      0x7fff86fc8000 -     0x7fff870dffef  libxml2.2.dylib 10.3.0 (compatibility 10.0.0) <1B27AFDD-DF87-2009-170E-C129E1572E8B> /usr/lib/libxml2.2.dylib
      0x7fff870e0000 -     0x7fff871fffe7  libcrypto.0.9.8.dylib 0.9.8 (compatibility 0.9.8) <14115D29-432B-CF02-6B24-A60CC533A09E> /usr/lib/libcrypto.0.9.8.dylib
      0x7fff87200000 -     0x7fff873befff  libicucore.A.dylib 40.0.0 (compatibility 1.0.0) <4274FC73-A257-3A56-4293-5968F3428854> /usr/lib/libicucore.A.dylib
      0x7fff875a1000 -     0x7fff875c2fff  libresolv.9.dylib 41.1.0 (compatibility 1.0.0) <9410EC7F-4D24-6740-AFEE-90405750FAD7> /usr/lib/libresolv.9.dylib
      0x7fff8880e000 -     0x7fff8884bff7  libssl.0.9.8.dylib 0.9.8 (compatibility 0.9.8) <F743389F-F25A-A77D-4FCA-D6B01AF2EE6D> /usr/lib/libssl.0.9.8.dylib
      0x7fff8885a000 -     0x7fff88910ff7  libobjc.A.dylib 227.0.0 (compatibility 1.0.0) <03140531-3B2D-1EBA-DA7F-E12CC8F63969> /usr/lib/libobjc.A.dylib
      0x7fff89fa1000 -     0x7fff89fccff7  libxslt.1.dylib 3.24.0 (compatibility 3.0.0) <8AB4CA9E-435A-33DA-7041-904BA7FA11D5> /usr/lib/libxslt.1.dylib
      0x7fff8a5aa000 -     0x7fff8a663fff  libsqlite3.dylib 9.6.0 (compatibility 9.0.0) <2C5ED312-E646-9ADE-73A9-6199A2A43150> /usr/lib/libsqlite3.dylib
      0x7fffffe00000 -     0x7fffffe01fff  libSystem.B.dylib ??? (???) <9AB4F1D1-89DC-0E8A-DC8E-A4FE4D69DB69> /usr/lib/libSystem.B.dylib

More info about my PHP environment:

'./configure' '--with-mysql=/Applications/MAMP/Library' '--with-apxs2=/Applications/MAMP/Library/bin/apxs' '--with-gd' '--with-jpeg-dir=/Applications/MAMP/Library' '--with-png-dir=/Applications/MAMP/Library' '--with-zlib' '--with-freetype-dir=/Applications/MAMP/Library' '--prefix=/Applications/MAMP/bin/php/php5.3.6' '--exec-prefix=/Applications/MAMP/bin/php/php5.3.6' '--sysconfdir=/Applications/MAMP/bin/php/php5.3.6/conf' '--with-soap' '--with-config-file-path=/Applications/MAMP/bin/php/php5.3.6/conf' '--enable-track-vars' '--enable-bcmath' '--enable-ftp' '--enable-gd-native-ttf' '--with-bz2=/usr' '--with-ldap' '--with-mysqli=/Applications/MAMP/Library/bin/mysql_config' '--with-sqlite' '--with-ttf' '--with-t1lib=/Applications/MAMP/Library' '--enable-mbstring=all' '--with-curl=/Applications/MAMP/Library' '--enable-dbx' '--enable-sockets' '--enable-bcmath' '--with-imap=shared,/Applications/MAMP/Library/lib/imap-2007e' '--enable-soap' '--with-kerberos' '--enable-calendar' '--with-pgsql=shared,/Applications/MAMP/Library/pg' '--enable-dbase' '--enable-exif' '--with-libxml-dir=/Applications/MAMP/Library' '--with-gettext=shared,/Applications/MAMP/Library' '--with-xsl=/Applications/MAMP/Library' '--with-pdo-mysql=shared,/Applications/MAMP/Library' '--with-pdo-pgsql=shared,/Applications/MAMP/Library/pg' '--with-mcrypt=shared,/Applications/MAMP/Library' '--with-openssl' '--enable-zip' '--with-iconv=/Applications/MAMP/Library'

subdomains pear.zero.mq and php.zero.mq not responding

I just ran 'pear upgrade' on my system and found
Error getting channel info from pear.zero.mq: Connection to `pear.zero.mq:80' failed: Connection timed out

same happens when trying to visit the documentation at php.zero.mq

ZMQ chainable?

In readme, ZMQ seems to be chainable:

$queue = new ZMQ(new ZMQContext(), ZMQ::SOCKET_REQ, "MySock1");
$queue->connect("tcp://127.0.0.1:5555");
var_dump($queue->send("hello there, using socket 1")->recv());

However I tried with the latest windows build it gave an error:
PHP Fatal error: Call to a member function recv() on a non-object

Thanks Mikko, this is a great extension!

Cheers,
Leng

Feature: Add callback on getSocket to execute on persistent socket creation

A persistent socked needs to be connected only once. It would be nice to use a callback to connect the socket upon creation instead of having to check manually.

Given this code which get the socket, check if there is any backend connected and connect them if not:

    $socket = $context->getSocket(ZMQ::SOCKET_DOWNSTREAM, 'mytest');
    $endpoints = $socket->getEndpoints();
    if (count($endpoints['connect']) <= 0) {
            // No endpoint, the socket just has been created
            $socket->connect("tcp://streamer.example.com:5550");
            $socket->connect("tcp://streamer.example.com:5551");
    }

I could instead do:

    function myconnect($cb_socket){
            $cb_socket->connect("tcp://streamer.example.com:5550");
            $cb_socket->connect("tcp://streamer.example.com:5551");
    }
    $socket = $context->getSocket(ZMQ::SOCKET_DOWNSTREAM, 'mytest', 'myconnect');

Wouldn't that be faster/simpler?

Segmentation Fault

I get a seg fault when trying to run the following script on the command line after installing php-zmq (I'm on commit b24cfaebd9250f983701a6112eed2d52240e14c6).

I'm on Ubuntu Lucid (PHP 5.3.2-1ubuntu4.2) with the latest ZeroMQ code from http://github.com/zeromq/zeromq2

Script to reproduce:

<?php
$c = new ZMQContext();
$s = $c->getSocket(ZMQ::SOCKET_UPSTREAM);
$s->connect("tcp://127.0.0.1:9997");

GDB Backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x00007fffee579862 in ?? () from /lib/libuuid.so.1
(gdb) bt
-0  0x00007fffee579862 in ?? () from /lib/libuuid.so.1
-1  0x00007fffee57a769 in uuid_generate () from /lib/libuuid.so.1
-2  0x00007fffec66cb89 in uuid_t (this=0x7ffff7fe5020) at uuid.cpp:84
-3  0x00007fffec66794e in zmq::socket_base_t::attach_pipes (this=0x117a270, inpipe_=0x117a650, outpipe_=0x0, peer_identity_=<value optimised out>)
    at socket_base.cpp:184
-4  0x00007fffec667f4b in zmq::socket_base_t::connect (this=0x117a270, addr_=<value optimised out>) at socket_base.cpp:414
-5  0x00007fffec885533 in zim_zmqsocket_connect (ht=<value optimised out>, return_value=0x1066cb8, return_value_ptr=<value optimised out>, 
    this_ptr=0x10667b8, return_value_used=<value optimised out>) at /home/dhotson/dev/php-zmq/zmq.c:581
-6  0x00007ffff4061f2a in xdebug_execute_internal (current_execute_data=0x7ffff7e8a068, return_value_used=0)
    at /build/buildd/xdebug-2.0.5/build-php5/xdebug.c:1631
-7  0x00000000006e5f36 in ?? ()
-8  0x00000000006bd400 in execute ()
-9  0x00007ffff4061b9e in xdebug_execute (op_array=0x1065590) at /build/buildd/xdebug-2.0.5/build-php5/xdebug.c:1562
-10 0x000000000069512d in zend_execute_scripts ()
-11 0x0000000000640d98 in php_execute_script ()
-12 0x0000000000726236 in ?? ()
-13 0x00007ffff52a8c4d in __libc_start_main () from /lib/libc.so.6
-14 0x000000000042c639 in _start ()

Any ideas?

failure to build on ubuntu 12.04

With the php and zeromq development headers installed, we can no longer build the extension, it appears to be as a result of f519700

   /bin/bash /tmp/pear/temp/pear-build-rootSTKOPM/zmq-1.0.4/libtool --mode=compile cc  -I. -I/tmp/pear/temp/zmq -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootSTKOPM/zmq-1.0.4/include -I/tmp/pear/temp/pear-build-rootSTKOPM/zmq-1.0.4/main -I/tmp/pear/temp/zmq -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/zmq/zmq.c -o zmq.lo
    libtool: compile:  cc -I. -I/tmp/pear/temp/zmq -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootSTKOPM/zmq-1.0.4/include -I/tmp/pear/temp/pear-build-rootSTKOPM/zmq-1.0.4/main -I/tmp/pear/temp/zmq -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/zmq/zmq.c  -fPIC -DPIC -o .libs/zmq.o
    /tmp/pear/temp/zmq/zmq.c:1433:2: error: 'zim_zmqcontext_setOpt' undeclared here (not in a function)
    /tmp/pear/temp/zmq/zmq.c:1434:2: error: 'zim_zmqcontext_getOpt' undeclared here (not in a function)
    /tmp/pear/temp/zmq/zmq.c:1504:2: error: 'zim_zmqsocket_unbind' undeclared here (not in a function)
    /tmp/pear/temp/zmq/zmq.c:1504:2: error: initializer element is not constant
    /tmp/pear/temp/zmq/zmq.c:1504:2: error: (near initialization for 'php_zmq_socket_class_methods[7].handler')
    /tmp/pear/temp/zmq/zmq.c:1505:2: error: 'zim_zmqsocket_disconnect' undeclared here (not in a function)
    /tmp/pear/temp/zmq/zmq.c:1505:2: error: initializer element is not constant
    /tmp/pear/temp/zmq/zmq.c:1505:2: error: (near initialization for 'php_zmq_socket_class_methods[8].handler')
    make: *** [zmq.lo] Error 1
    ERROR: `make' failed

poll->remove bug

------------------------------------php file-----------------------------------------


<?php
$context=new ZMQContext(1, false);
$server=new ZMQSocket($context, ZMQ::SOCKET_XREP);
$server->bind('inproc://test');
$client=new ZMQSocket($context, ZMQ::SOCKET_XREQ);
$client->connect('inproc://test');
$client2=new ZMQSocket($context, ZMQ::SOCKET_XREQ);
$client2->connect('inproc://test');
$poll=new ZMQPoll();
$poll->add($server, ZMQ::POLL_IN);
$poll->add($client, ZMQ::POLL_IN);
$poll->add($client2, ZMQ::POLL_IN);
$readable = array();
$writable = array();
for($i=0;$i<20;$i++)
{  
    if($i===10)
    {
        $result=$poll->remove($client);
        if($result!==true)
        {
            print_r($poll->getLastErrors());
        }
    }
    if($i%2)
    {
        $client->send('client1 '.$i);
    }
    else
    {
        $client2->send('client2 '.$i);
    }
    $event=$poll->poll($readable, $writable, 1);
    if(!$event)
    {
        continue;
    }
    foreach ($readable as $socket)
    {
        $msg=$socket->recvMulti();
        if($socket===$server)
        {
            echo 'client to server msg:'.print_r($msg[1], true).PHP_EOL;
        }
        else
        {
            echo 'server to client msg:'.print_r($msg[1], true).PHP_EOL;
        }
    }
}
?>

------------------------------------php file-----------------------------------------

------------------------------------php result-----------------------------------------
client to server msg:client2 0
client to server msg:client1 1
client to server msg:client2 2
client to server msg:client1 3
client to server msg:client2 4
client to server msg:client1 5
client to server msg:client2 6
client to server msg:client1 7
client to server msg:client2 8
client to server msg:client1 9
------------------------------------php result-----------------------------------------

------------------------------------bug description-----------------------------------------
$result=$poll->remove($client2);
only remove $client2, but $client same remove ?
look like if remove one, then clear all poll list.
------------------------------------bug description-----------------------------------------

------------------------------------php info-----------------------------------------
PHP Version => 5.3.10

System => Darwin localhost 11.2.0 Darwin Kernel Version 11.2.0: Tue Aug 9 20:54:00 PDT 2011; root:xnu-1699.24.8~1/RELEASE_X86_64 x86_64
Build Date => Feb 10 2012 14:47:34
Configure Command => './configure' '--prefix=/usr' '--disable-all' '--enable-cli' '--with-curl' '--with-zmq' '--enable-json' '--enable-memcached' '--disable-memcached-session' '--disable-cgi' '--with-rune' '--disable-ipv6' '--with-zlib-dir=/opt/local'
Server API => Command Line Interface
------------------------------------php info-----------------------------------------

------------------------------------php-zmq info-----------------------------------------
mkoppanen-php-zmq-1.0.2-2-g2d1fb76.zip
------------------------------------php-zmq info-----------------------------------------

new bug for fix version ( 87d3e5c Fixes GH-50 )

GH-50 same php file now result:

client to server msg:client2 0
client to server msg:client1 1
client to server msg:client2 2
client to server msg:client1 3
client to server msg:client2 4
client to server msg:client1 5
client to server msg:client2 6
client to server msg:client1 7
client to server msg:client2 8
client to server msg:client1 9
client to server msg:client2 10
client to server msg:client1 11
client to server msg:client2 12
client to server msg:client1 13
client to server msg:client2 14
client to server msg:client1 15
client to server msg:client2 16
client to server msg:client1 17
client to server msg:client2 18
client to server msg:client1 19

look this line $result=$poll->remove($client);
client1 still here ?
poll->remove method become invalid.

throughput issue

Hello,

I have started zeromq with your server script. (Zeromq and php module has been successfully installed.)

Server script

bind("tcp://127.0.0.1:5555"); /\* Loop receiving and echoing back _/ while ($message = $server->recv()) { echo "Got message: $message\n"; /_ echo back the message */ $server->send($message); } ## ?>

Client script:

connect("tcp://127.0.0.1:5555"); echo "Start Time:-" . date("Y-m-d H:i:s") . "\n"; /\* Assign socket 1 to the queue, send and receive */ for ($i = 0; $i <= 100000; $i++) { $queue->send("hello there!-$i"); $queue->recv(); } echo "End Time:-" . date("Y-m-d H:i:s") . "\n"; ## ?>

I have run this script in two different console of server via ssh and complete time taken for 100000 is 21 sec. Is it up to the mark..? I think no as i have seen some blog which says that they have got 5500000/sec...can you please check if i am doing some mistake while doing throughput test.

Do i need to use persistent some where to get optimum throughput?

Regards
Tapan Thapa
[email protected]

library load error in php

Trying to get it going on latest centos 32bit.

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/zmq.so' - /usr/lib/php/modules/zmq.so: undefined symbol: php_spl_object_hash in Unknown on line 0
[Tue Jul 06 10:03:36 2010] [notice] Apache/2.2.3 (CentOS) PHP/5.2.13 mod_ssl/2.2.3 OpenSSL/0.9.8e-fips-rhel5 configured -- resuming normal operations

I tried building all libs seem to be in the right places during both building of libzmq and php zmq.

Any ideas?

Messages sent upstream/downstream can be lost on php exit

I want to send a message to a subscriber without waiting on a response. But i found if my php script exits too quickly, the message doesn't arrive to my subscriber.

here is how to reproduce the bug:

create a simple php script called server.php.

bind("tcp://127.0.0.1:5555");
while ($message = $server->recv()) echo "Got message: $message\n";
?>

create another script called client.php:

connect("tcp://127.0.0.1:5555");
if( $queue->send("hello there!") ) print "message sent\n";
if( $arg ) usleep($arg);
?>

in one terminal, do:

php server.php

in another, do:

php client.php 0
php client.php 10
php client.php 100
php client.php 1000
php client.php 10000

if you increase the wait time beyond a certain point, the message shows up. May differ on your machine, but on average it seems i have to wait 150 microseconds or my message never shows up at all. Perhaps because php's garbage collection is killing the message before it gets sent?

Memory leak

I have created two scripts to test performance of PHP binding and found Memory leak.

pub https://gist.github.com/3308329
sub https://gist.github.com/3308327

sub eats memory very fast (over 2GB in 2-3 minutes). Pub looks stable at 10.1MB.

memory_get_usage() function shows stable memory usage of 327996.

On side note, node.js binding is showing msg rate of 60k/sec while PHP binding is showing rate of 400k/sec. I wounder if I am doing something wrong.

problem with zmq work with libevent in php

//myserver
function print_line($fd, $events, $arg) {
static $msgs = 1;
echo "CALLBACK FIRED" . PHP_EOL;
echo $arg[0]->recv();
if($arg[0]->getsockopt (ZMQ::SOCKOPT_EVENTS) & ZMQ::POLL_IN) {
echo "Got incoming data" . PHP_EOL;
var_dump ($arg[0]->recv());
}
}
$base = event_base_new();
$event = event_new();
$context = new ZMQContext();
$rep = $context->getSocket(ZMQ::SOCKET_PULL);
$rep->bind("tcp://192.168.2.112:5555");
$fd = $rep->getsockopt(ZMQ::SOCKOPT_FD);
event_set($event, $fd, EV_READ | EV_PERSIST, "print_line", array($rep, $base));
event_base_set($event, $base);
event_add($event);
event_base_loop($base);

//client
for($i=0;$i<10;$i++) {
testSend($i);
}

function testSend($i)
{
if (!$queue) {
$queue = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_PUSH, "MySock1");
$queue->connect("tcp://192.168.2.112:5555");
}
$msg = "testword{$i}\r\n";
$queue->send($msg);
echo "done{$i}\r\n";
}

problem: i can only receive the first msg; but when i use zmq only on my server it works ok;
like this

$context = new ZMQContext();
$responder = new ZMQSocket($context, ZMQ::SOCKET_PULL);
$responder->bind('tcp://192.168.2.112:5555');
try{
while ($request = $responder->recv()) {
echo 'Message received...'.$request . "\n";
}
} catch (ZMQSocketException $e) {
print_r($e);
}

How I want to solve this problem?

Cannot set ZMQ_LINGER to -1

The zmq.c code appears to disallow setting the ZMQ_LINGER socket option to -1, although this is an allowed value (see http://api.zeromq.org/master:zmq-setsockopt#toc15).

e.g.
$s1->setsockopt(ZMQ::SOCKOPT_LINGER, -1);

has no effect.

(fyi - I am wrapping the php-zmq binding into the hxzmq haXe binding, to allow haXe to use zmq via cpp, neko or php).

Warm regards,

Richard

configure: error: Unable to find libzmq installation

Encountering the following when I try to configure php-zmq:

$ ./configure
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /opt/local/bin/gsed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... i686-apple-darwin10.4.0
checking host system type... i686-apple-darwin10.4.0
checking target system type... i686-apple-darwin10.4.0
checking for PHP prefix... /opt/local
checking for PHP includes... -I/opt/local/include/php -I/opt/local/include/php/main -I/opt/local/include/php/TSRM -I/opt/local/include/php/Zend -I/opt/local/include/php/ext -I/opt/local/include/php/ext/date/lib -I/opt/local/include
checking for PHP extension directory... /opt/local/lib/php/extensions/no-debug-non-zts-20090626
checking for PHP installed headers prefix... /opt/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether to enable 0MQ support... yes, shared
checking for pkg-config... /opt/local/bin/pkg-config
checking libzmq installation... configure: error: Unable to find libzmq installation

ZMQDevice::__construct() expects exactly 2 parameters, 3 given

Running the PHP example "msgqueue.php" from the zguide repo results in a warning and a segfault.

PHP Warning: ZMQDevice::__construct() expects exactly 2 parameters, 3 given in ./zguide/examples/PHP/msgqueue.php on line 20
Segmentation fault

Not sure why ZMQDevice::__construct() expects only 2 parameters. It doesn't look that way looking at zmq.c, not sure how to suggest a fix.

Total system memory growing

I am testing the zeromq lib and the php extension for a project that will receive a huge number of messages from a huge number of clients. Practically what I have in my benchmark scenario is (all on the same Linux RH5u3 machine 64bit with PHP 5.3.2):

  1. One php script that acts as the injector that forks into 100 children, each of them building a random messages (always the same length) that is sent each second. The sending is done using a persistent socket of type PUSH using a dns of type ipc.
  2. The server script once started will fork into 20 children, each of them will bind to the same dns mentioned previously using a socket of type PULL. The parent process in the server binds to a command socket of type PULL on a different dns, also of type ipc (in my benchmark I do not test this command socket).

Each client does something like:

$socket = new \ZMQSocket(new \ZMQContext(), \ZMQ::SOCKET_PUSH);
$socket->connect($dsn);

for ($iterator = 0; $iterator < $eventsNb; $iterator++) {
    // build $message here .....

    $socket->send($message);
    sleep(1);
}

The server workers do something like:

$context = new \ZMQContext();

// socket to receive messages on
$requestSocket = new \ZMQSocket($context, \ZMQ::SOCKET_PULL);
$requestSocket->bind($requestDns);

// command socket to notify the workers
$commandSocket = new \ZMQSocket($context, \ZMQ::SOCKET_SUB);
$commandSocket->connect($commandDns);
$commandSocket->setSockOpt(\ZMQ::SOCKOPT_SUBSCRIBE, '');

// put all input sockets inside a poll
$poll = new \ZMQPoll();
$poll->add($requestSocket, \ZMQ::POLL_IN);
$poll->add($commandSocket, \ZMQ::POLL_IN);

$readable = $writeable = array();

// process messages from all input sockets
while (true) {
    // amount of events retrieved
    $events = 0;

    try {
        // poll until there is something to do
        $events = $poll->poll($readable, $writeable);
        $errors = $poll->getLastErrors();

        if (count($errors) > 0) {
            foreach ($errors as $error) {
                // log error
            }
        }
    } catch (ZMQPollException $e) {
        // log error
        continue;
    }
    if ($events > 0) {
        foreach ($readable as $socket) {
            // get the message
            //  multipart message detection
            $parts = array();

            while (true) {
                try {
                    $parts[] = $socket->recv();
                } catch (\ZMQException $e) {
                    continue;
                }

                if (!$socket->getSockOpt(\ZMQ::SOCKOPT_RCVMORE)) {
                    break;
                }
            }

            $message = $parts[count($parts) - 1];

            if ($socket === $requestSocket) {
                // do the work
                processMessage($message);
            } else if ($socket === $commandSocket) {
                processCommand($message);
            }
        }
    }
}

Here is the graph that shows what is happening to the system memory and all the workers PHP scripts during a 12 hour run time:
http://dl.dropbox.com/u/14630102/mem_increase.png

Do you have any clue what is going on?

Compile fails w/ php 5.2.6

As emailed:

Hi there!

I was testing out your zeromq php module - when doing a compile:

/bin/sh /development/zeromq/php/php-zeromq/libtool --mode=compile gcc -I. -I/development/zeromq/php/php-zeromq -DPHP_ATOM_INC -I/development/zeromq/php/php-zeromq/include -I/development/zeromq/php/php-zeromq/main -I/development/zeromq/php/php-zeromq -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /development/zeromq/php/php-zeromq/zeromq.c -o zeromq.lo
gcc -I. -I/development/zeromq/php/php-zeromq -DPHP_ATOM_INC -I/development/zeromq/php/php-zeromq/include -I/development/zeromq/php/php-zeromq/main -I/development/zeromq/php/php-zeromq -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /development/zeromq/php/php-zeromq/zeromq.c -fPIC -DPIC -o .libs/zeromq.o
In file included from /development/zeromq/php/php-zeromq/zeromq.c:31:
/development/zeromq/php/php-zeromq/php_zeromq.h:50:28: warning: no newline at end of file
/development/zeromq/php/php-zeromq/zeromq.c: In function 'PHP_INI_BEGIN':
/development/zeromq/php/php-zeromq/zeromq.c:638: error: expected declaration specifiers before 'STD_PHP_INI_ENTRY'
/development/zeromq/php/php-zeromq/zeromq.c:649: error: expected '=', ',', ';', 'asm' or 'attribute' before '{' token
/development/zeromq/php/php-zeromq/zeromq.c:710: error: expected '=', ',', ';', 'asm' or 'attribute' before '{' token
/development/zeromq/php/php-zeromq/zeromq.c:716: error: expected '=', ',', ';', 'asm' or 'attribute' before '{' token
/development/zeromq/php/php-zeromq/zeromq.c:727: error: parameter 'zeromq_module_entry' is initialized
/development/zeromq/php/php-zeromq/zeromq.c:732: error: 'zm_startup_zeromq' undeclared (first use in this function)
/development/zeromq/php/php-zeromq/zeromq.c:732: error: (Each undeclared identifier is reported only once
/development/zeromq/php/php-zeromq/zeromq.c:732: error: for each function it appears in.)
/development/zeromq/php/php-zeromq/zeromq.c:733: error: 'zm_shutdown_zeromq' undeclared (first use in this function)
/development/zeromq/php/php-zeromq/zeromq.c:736: error: 'zm_info_zeromq' undeclared (first use in this function)
/development/zeromq/php/php-zeromq/zeromq.c:742: error: expected '=', ',', ';', 'asm' or 'attribute' before '{' token
/development/zeromq/php/php-zeromq/zeromq.c:743:31: warning: no newline at end of file
/development/zeromq/php/php-zeromq/zeromq.c:727: error: declaration for parameter 'zeromq_module_entry' but no such parameter
/development/zeromq/php/php-zeromq/zeromq.c:742: error: expected '{' at end of input

It seems to be choking on this:

PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("zeromq.app_threads", "1", PHP_INI_ALL, OnUpdateLong, app_threads, zend_zeromq_globals, zeromq_globals)
STD_PHP_INI_ENTRY("zeromq.io_threads", "1", PHP_INI_ALL, OnUpdateLong, io_threads, zend_zeromq_globals, zeromq_globals)
PHP_INI_END()

and to fix - i added this include at the top:

include "php_ini.h"

and now it compiles perfect.

This is on CentOS 5.3 with php 5.2.6.

I don't know if I missed something, or you need to update the source -- regardless, I thought I'd let you know. Thanks for your work!

Signal handling broken

Hi

The program should receive a kill -HUP <pid>, but while recv() is waiting for a message, the signal will not be received. It works in C but not in PHP.

  • Operating System: FreeBSD 8.2-RELEASE (i386)
  • PHP: 5.3.6 (with Xdebug v2.1.0)
  • zmq: 2.1.7
  • php-zmq: Fri Jun 3 09:17:33 2011 +0100 (b200f9d)

I'm not sure if it is a general PHP or php-zmq problem.

Thank you for your great work.

Best regards,
Dom

PHP version

declare(ticks = 1);

echo posix_getpid() . "\n";

pcntl_signal(SIGHUP, 'sigHandler');

$context = new ZMQContext();
$responder = new ZMQSocket($context, ZMQ::SOCKET_REP);
$responder->bind('tcp://127.0.0.1:5559');

//while (true) {
//    echo '.'; 
//    sleep(1);
//}

while ($request = $responder->recv()) {
    echo 'Message received...' . "\n";
}

function sigHandler()
{
    echo "Caught SIGHUP...\n";
}

C version

void sig_func(int sig)
{
    write(1, "Caught signal HUP\n", 18);
}

int main()
{
    signal(SIGHUP, sig_func);

    void *context = zmq_init (1);

    void *responder = zmq_socket (context, ZMQ_REP);
    zmq_bind (responder, "tcp://*:5555");

    while (1) {
        zmq_msg_t request;
        zmq_msg_init (&request);
        zmq_recv (responder, &request, 0);
        printf ("Received Hello\n");
        zmq_msg_close (&request);
    }
    zmq_close (responder);
    zmq_term (context);
    return 0;
}

Forked children cause assertion failure

I'm trying wo write a worker that forks its self to process tasks. This means that the Context is created pre-fork. I'm running into a problem where when the child process exits, it triggers an assertion error (presumably) when it's trying to clean up the context/threads it inherited from the parent:

Assertion failed: ok (mailbox.cpp:84)

The code I'm using to produce this is here: https://gist.github.com/2939834
The error occurs on line 41, where the child calls exit();

Any ideas?

Class ZMQSocket not found on Windows

I downloaded and installed the php_zmq DLL from here and when I try to run the client.php example code I get this error:

PHP Fatal error:  Class 'ZMQSocket' not found in C:\[...]\client.php on line 9

Fatal error: Class 'ZMQSocket' not found in C:\[...]\client.php on line 9

The extension is installed, because when I run php --ri zmq I get this:

zmq

ZMQ extension => enabled
ZMQ extension version => @PACKAGE_VERSION@
libzmq version => 2.0.10

Directive => Local Value => Master Value
zmq.persist_context => 1 => 1

When I run php --re zmq it only lists the following classes: ZMQ, ZMQPoll, ZMQException and ZMQPollException.

Thanks in advance for any help.

Permission denied

Hi,

I am using nginx to serve a web app. I get permission denied when i try to bind or connect a 0mq socket. I have chmodded the relevant directories but I am unsure what else to do about this.

Using array references with Poller: arrays not populated

When using array references for $readable and $writeable, the arrays are not populated.
Reproducing code below (see the comment for PollWrapper::poll())

Server code:

<?php

$socket = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_PUB);
$socket->bind('tcp://*:7001');

while (true) {
    $now = time();
    $socket->send($now);
    echo "published $now\n";
    sleep(1);
}

and the client code:

<?php

$socket = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_SUB);
$socket->connect('tcp://127.0.0.1:7001');
$socket->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, "");

class PollWrapper
{
    public function __construct($socket)
    {
        $this->poller = new ZMQPoll();
        $this->poller->add($socket, ZMQ::POLL_IN | ZMQ::POLL_OUT);
    }

    // using references here -> arrays not populated. Remove the references to make it work
    public function poll(&$readable, &$writeable, $timeout = 0)
    {
        $return = $this->poller->poll($readable, $writeable, $timeout);
        var_dump($readable);
        var_dump($writeable);

        return $return;
    }
}

$pollObj = new PollWrapper($socket);

while (true)
{
    $readable = $writeable = array();
    $events = $pollObj->poll($readable, $writeable, -1);

    if ($events == 0) {
        echo "No events\n";
        sleep(1);
    } else if (count($readable) == 0 && count($writeable) == 0) {
        echo "Event arrays are empty :(\n";
        exit(1);
    }
}

64 Bit Version

I downloaded source and tried to build the dll so that I could get it to work on my machine but had no luck. The issue I ran into is it couldn't find php.h which is in the php_zmq.h file.

Where do I get that? Is there a compiled version already out there somewhere?

This is what I have done to try and solve the problem:
I have downloaded the files here:
http://snapshot.zero.mq/

I took the libzmq.dll from 64 bit version and that appears to work but when it tries to load the php_zmq.dll (referenced in the php.ini file) it doesn't work from the php_ext3 package (haven't been able to see any others). Either threaded or non threaded.

So I thought hey there is some source I will just build the code. But I guess my inexperience is getting the best of me. I am unable to build it from the source. I typed cl zmq.c and got the unable to find php.h error (mentioned above).

Any help would be appreciated.

This is appears to be a great solution. I was able to get it up and running in our testing environment (linux) and it works great; but we need to be able to get it working on our local boxes for development purposes. The local environment is Win64 running php 5.3.0 and apache 2.2.12 (Used Xampp to install). Hence the problem I am having.

Thanks for the help.
--Eric

zmq.so mach-o, but wrong architecture

Hi Mikko,

I am trying to make it work on my OSX 10.6.6 and it compiles fine as far as I can tell, but i get this in apache logs when starting up:

[21-Mar-2011 00:31:56] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/zend/lib/php_extensions/zmq.so' - dlopen(/usr/local/zend/lib/php_extensions/zmq.so, 9): no suitable image found.
Did find: /usr/local/zend/lib/php_extensions/zmq.so: mach-o, but wrong architecture in Unknown on line 0

Any advise on what can be tweaked to make this work?

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.