php-zmq icon indicating copy to clipboard operation
php-zmq copied to clipboard

Please fix api.php

Open giac opened this issue 14 years ago • 21 comments
trafficstars

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 d44061f6aecf711a457ff516c9e4d80babf4137

Thanks for your work!

giac avatar Aug 03 '11 10:08 giac

Hi,

i think better idea might be creating a script that creates api.php automatically. This file is really needed only for eclipse and the like code completion.

mkoppanen avatar Aug 04 '11 21:08 mkoppanen

I also got the same problem. I imported it into PHPStorm IDE and get fatal errors about missing constants.

Will be this api.php file fixed soon?

aik099 avatar Mar 02 '12 18:03 aik099

It appears that most accurate version is here http://php.zero.mq/, but you can't really download all class declarations from there.

aik099 avatar Mar 02 '12 18:03 aik099

Hi,

this should be fairly easy task with reflection. I'll try to update it today

mkoppanen avatar Mar 03 '12 00:03 mkoppanen

Any progress on this one?

I can use Reflection API to get names of constants and method, but how do I get these nice PHPDoc documentation for each of them?

aik099 avatar Mar 11 '12 11:03 aik099

had the same problem (for other extensions too) so i created DocThor

ZMQ-API v1.0.3 is the example

but you can build your own with it

SegFaulty avatar Mar 30 '12 22:03 SegFaulty

This is excellent. I am very short on time at the moment but I'll use DocThor to generate new api.php

mkoppanen avatar Mar 30 '12 22:03 mkoppanen

Are you sure that https://github.com/SegFaulty/DocThor/wiki/zmq is generated according to latest version of php extension?

ZMQDevice constructor should have 3 arguments: $device_type $frontend $backend

according to their C api http://api.zeromq.org/2-1:zmq-device and PHP samples http://zguide.zeromq.org/php:msgqueue.

I'm actually trying to create new version of api.php file with all comments are references to API website to create more useful hints in auto-complete.

Maybe there is an error in PHP bindings.

aik099 avatar Mar 31 '12 07:03 aik099

first: https://github.com/SegFaulty/DocThor/wiki/zmq is updated , now with some more information from the source (new DocThor Feature --sourceDir)

ZMQDevice .. don't know, you are right the examples refer 3 arguments but I get: $device = new ZMQDevice(ZMQ::DEVICE_QUEUE, $frontend, $backend); _Warning: ZMQDevice::_construct() expects exactly 2 parameters, 3 given in ,, AND i have to use ZMQDevice::run()

a look at the extension sources here https://github.com/mkoppanen/php-zmq/blob/master/zmq.c#L1138 shows 2 args

SegFaulty avatar Mar 31 '12 20:03 SegFaulty

I removed the first arg as it had no effect.

mkoppanen avatar Mar 31 '12 21:03 mkoppanen

well, that explains it...

btw. with the newest DocThor feature, i found:

8 inconsistencies
inconsistent parameter name: ZMQContext::__construct reflection:persistent sourceCode:is_persistent
inconsistent parameter name: ZMQSocket::__construct reflection:ZMQContext sourceCode:context
inconsistent parameter name: ZMQSocket::send reflection:mode sourceCode:flags
inconsistent parameter name: ZMQSocket::sendmulti reflection:message sourceCode:messages
inconsistent parameter name: ZMQSocket::sendmulti reflection:mode sourceCode:flags
inconsistent parameter name: ZMQPoll::add reflection:entry sourceCode:object
inconsistent parameter name: ZMQPoll::add reflection:type sourceCode:events
inconsistent parameter name: ZMQPoll::remove reflection:remove sourceCode:item

minor .. but maybe related to this issue :-)

SegFaulty avatar Mar 31 '12 21:03 SegFaulty

Since current PHP bindings were out there for quite a long time, then maybe in PHP there is another way to specify device type, but I really don't know how.

aik099 avatar Apr 01 '12 07:04 aik099

The device type has never made any difference. If you look at ZeroMQ source the device type parameter is ignored.

mkoppanen avatar Apr 01 '12 07:04 mkoppanen

I've just noticed that this page http://api.zeromq.org/2-0-11:_start is API documentation for ZeroMQ 2.0.11, where zmq_device function exists and it has 3 parameters.

But I'm using 2.1.11 (http://api.zeromq.org/2-1-1:_start) version of ZeroMQ library where there is no zmq_device function and instead a separate functions are created:

  • zmq_streamer
  • zmq_poll
  • zmq_queue

This makes me think, that they should be represented as a separate ZMQDevice class descendants in PHP bindings.

aik099 avatar Apr 01 '12 07:04 aik099

From documentation: If you're like most ØMQ users, at this stage your mind is starting to think, "what kind of evil stuff can I do if I plug random socket types into devices?" The short answer is: don't do it. You can mix socket types but the results are going to be weird. So stick to using ROUTER/DEALER for queue devices, SUB/PUB for forwarders and PULL/PUSH for streamers.

Maybe in PHP bindings it's automatic - device type is matched to socket type you pass, while creating a device?

aik099 avatar Apr 01 '12 07:04 aik099

If you look a the actual ZeroMQ 2.1.x source code here:

https://github.com/zeromq/zeromq2-1/blob/master/src/zmq.cpp#L764

The 'int device' parameter is passed (which is the device type) but when the actual device code is called it's not being passed on. The device type parameter exists there only for backwards compatibility i think.

mkoppanen avatar Apr 01 '12 07:04 mkoppanen

I would appreciate if someone would provide step by step docthor instructions which i can link to.

mkoppanen avatar Nov 28 '12 08:11 mkoppanen

@mkoppanen: see the Example section of DocThor's README.

phuedx avatar Jun 04 '14 10:06 phuedx

I've just run DocThor against master and this is the result: https://gist.github.com/phuedx/5f727191b30fd8969825

phuedx avatar Feb 04 '15 14:02 phuedx

Alright, so, as HHVM does require native functions to be properly declared, I have a version of the API that should be almost identical to the actual one, although documentation is needed for anything that wasn't in the original api.php, which I've marked with @EXTRA. Here is the main file. That file includes the documentation that was already there, but doesn't include any of the constants that are defined. Changes will have to be made to that as it's marked up for direct use in HHVM, so pretty much everything is strongly typed in the API. For a complete list of constants, you'd see here, which is the Hack API file for it. All documentation was stripped from the second file. Note that the constant list is based on a build against ZMQ v4.

Orvid avatar Sep 10 '15 03:09 Orvid

Hi, it's not fixed yet ? All the constants are inserted in the ZMQ class.

https://github.com/mkoppanen/php-zmq/blob/master/api.php

alvaro-osvaldo-tm avatar Apr 26 '17 23:04 alvaro-osvaldo-tm