php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65597 Can't use sockets with MacPorts
Submitted: 2013-08-30 21:00 UTC Modified: 2013-09-08 11:53 UTC
From: miken32 at gmail dot com Assigned: osmanov (profile)
Status: Closed Package: event (PECL)
PHP Version: 5.4.19 OS: OS X 10.7.5
Private report: No CVE-ID: None
 [2013-08-30 21:00 UTC] miken32 at gmail dot com
Description:
------------
I installed PHP and the sockets extension via MacPorts, and built this extension 
manually without any errors. But I was unable to use sockets, only stream 
resources.

Some digging through the code turned up a check in common.h for HAVE_SOCKETS or 
COMPILE_DL_SOCKETS which were both undefined at compile time. I don't know enough 
about C programming to say much, but the MacPorts folks suggested that your code 
could be changed to check for the presence of the sockets extension another way.




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-04 15:43 UTC] osmanov@php.net
It looks like you have to install a "development package". I'm not an OS X
user, so don't know exactly the name of the package.  Linux distributions often
call it something like "php-dev", "php5-dev", "php-devel" etc.

I guess it had merely been compiled without sockets support as the latter is not 
required currently.

Unfortunately, there is no reliable cross-platform way to detect whether
sockets ext. is present. At least I don't know such way. Both compile-time and
run-time checks have their drawbacks. Just try to install development files of 
PHP.

Let me know how it will go.
 [2013-09-04 16:12 UTC] miken32 at gmail dot com
That's what I figured was the case. There is no development package in MacPorts, 
it looks like all header files, phpize, etc. are installed with the normal 
package. I'm not sure that it would be able to help in this case anyway, where 
the sockets extension is built separately and loaded dynamically.
 [2013-09-06 17:19 UTC] osmanov@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: osmanov
 [2013-09-06 17:19 UTC] osmanov@php.net
Sorry, for some reason I don't receive E-mail from this tracker.

I've just added --enable-event-sockets configure option:
https://bitbucket.org/osmanov/pecl-event

Sockets extension is now required by default. However, this requirement can be 
turned off with --disable-event-sockets option. Package maintainers should 
handle this, btw.

If it's okay, I'll package it ASAP.
 [2013-09-07 07:16 UTC] osmanov@php.net
Uploaded version 1.7.6
 [2013-09-08 02:44 UTC] php-bugs-2013 at ryandesign dot com
Building 1.7.6 with or without --enable-event-sockets doesn't work; it says:

src/util.c:30:2: error: unknown type name 'php_socket'; did you mean 
'php_socket_t'?

I still need to manually add -DHAVE_SOCKETS to CFLAGS, as I had to to build 1.7.5.
 [2013-09-08 07:42 UTC] osmanov@php.net
> Building 1.7.6 with or without --enable-event-sockets doesn't work 
Without --enable-event-sockets this option is implied to be *on*. To disable 
sockets one should use --disable-event-sockets option, which turns off sockets 
support. This means that the sockets extension is required by default, but if 
you configure with --disable-event-sockets, then sockets support is ignored 
completely.

You shouldn't define HAVE_SOCKETS yourself anyway. It should be detected 
automatically.

Moreover, I had removed the checks for HAVE_SOCKETS and COMPILE_DL_SOCKETS.
Instead, I made sockets required(unless --disable-event-sockets option used):

https://bitbucket.org/osmanov/pecl-
event/src/f4809f12b66539bdef7b2f003b77be7b7fffde4f/src/common.h?at=master#cl-37
https://bitbucket.org/osmanov/pecl-
event/src/f4809f12b66539bdef7b2f003b77be7b7fffde4f/config.m4?at=master#cl-214

In config.m4:
if test "$PHP_EVENT_SOCKETS" != "no"; then
    PHP_ADD_EXTENSION_DEP(event, sockets)
    AC_DEFINE(PHP_EVENT_SOCKETS, 1, [Sockets extension is required])
fi

PHP_ADD_EXTENSION_DEP without 3rd argument makes extension required.

In php_event.c:
https://bitbucket.org/osmanov/pecl-
event/src/f4809f12b66539bdef7b2f003b77be7b7fffde4f/php_event.c?at=master#cl-61

So the sockets extension is required by default, and the checks for its presence 
are made by PHP
in both compile-time and run-time cases.

To build Event successfully we need:
* PHP headers including "ext/sockets/php_sockets.h"(for instance, on my Gentoo I 
have it here: /usr/lib/php5.4/include/php/ext/sockets/php_sockets.h)
* PHP built with --enable-sockets
* phpize version should match php version, namely(my version):
$ phpize --version 

Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525


$ php -i | perl -e 'while(<>){/^(Zend|PHP) / and print $_;}'
PHP Version => 5.4.19-pl0-gentoo
PHP API => 20100412
PHP Extension => 20100525
Zend Extension => 220100525
Zend Extension Build => API220100525,NTS,debug
PHP Extension Build => API20100525,NTS,debug
Zend Signal Handling => disabled
Zend Memory Manager => enabled
Zend Multibyte Support => provided by mbstring
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
PHP Version => 5.4.19-pl0-gentoo

Probably, you have different versions of PHP installed. Probably, phpize implies 
another version of PHP.

If it still fails, I can also try to help you via SSH, if you wish.
 [2013-09-08 09:02 UTC] osmanov@php.net
-Status: Closed +Status: Re-Opened
 [2013-09-08 09:02 UTC] osmanov@php.net
Hmm, I see that $PHP_SOCKETS variable is actually empty when sockets are 
disabled. It means that PHP_ADD_EXTENSION_DEP won't stop with error, since it 
check for "no" string:
http://bpaste.net/show/130476/

With a little hack in our config.m4:
  if test "x$PHP_SOCKETS" = "x"; then
    PHP_SOCKETS="no"
  fi

it'll stop configuration with the following error:
configure: error: 
You've configured extension event, which depends on extension sockets,
but you've either not enabled sockets, or have disabled it.

At least, the user can now understand that he/she needs to rebuild PHP with 
sockets enabled.

I'll ask for clarification on the PECL mailing list/IRC.

Let me know if you have ideas, too.
 [2013-09-08 11:53 UTC] osmanov@php.net
-Status: Re-Opened +Status: Closed
 [2013-09-08 11:53 UTC] osmanov@php.net
Okay, I figured it out.

The config.m4 macro is used to static building only. The required module 
dependency is checked at run time only.

Our compilation error is caused by absence of defined HAVE_SOCKETS symbol, which 
is normally stored in main/php_config.h when PHP is built with --enable-sockets 
option. But ext/sockets/php_sockets.h wraps all of its code in #if HAVE_SOCKETS 
block.

Working in Gentoo I almost forgot that some distributions use separate packages 
even for the standard extensions bundled with the PHP source. So installing 
"sockets" separately we have no HAVE_SOCKETS symbol defined anywhere.

I've just pushed a workaround. Please checkout the Git version. Unfortunately, 
we've no other way than to define HAVE_SOCKETS ourselves. I'm just checking for 
ext/sockets/php_sockets.h. If the header is present and usable, I define 
HAVE_SOCKETS.

I should work this time. If it's okay, I'll upload new package to PECL.

Thanks.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun May 19 15:01:26 2019 UTC