# Patch - create socket by fd#

- Thread: https://externals.io/message/52443
- Original archive: https://news-web.php.net/php.internals/52443
- Started by Florian Wilkemeyer on 2011-05-18T10:44:35+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #52443 — Florian Wilkemeyer — 2011-05-18T10:44:35+00:00

URL: https://externals.io/message/52443#52443

Hi,

i recently wrote small function that allows the creation of a php-socket 
by directly giving the fd#

this is very useful under linux/unix environments for Ipc.
For example:
getting forked by a webserver as fastcgi / scgi .., the webserver gives 
an acceptable socket as fd#0 to the process..

I submitted the patch about 3 weeks ago @ pecl-dev list in the fdpass 
extension topic.

It would be nice to see such function in dist php :)


Florian

---

## #52444 — Gustavo Lopes — 2011-05-18T11:13:36+00:00

URL: https://externals.io/message/52443#52444 · In reply to: #52443

Em Wed, 18 May 2011 11:44:35 +0100, Florian Wilkemeyer <fw@f-ws.de>  
escreveu:

> i recently wrote small function that allows the creation of a php-socket
> by directly giving the fd#
>
> this is very useful under linux/unix environments for Ipc.
> For example:
> getting forked by a webserver as fastcgi / scgi .., the webserver gives
> an acceptable socket as fd#0 to the process..
>
> I submitted the patch about 3 weeks ago @ pecl-dev list in the fdpass
> extension topic.
>
> It would be nice to see such function in dist php :)
>

I can commit this, but a few changes are required first:

* This doesn't work on Windows, so it should be ifdef'd out on that  
platform.
* The family can be detected
* The blocking behavior should be queried, not hardcoded to 1
* This patch is not up-to-date with trunk/5.4 (see php_create_socket)

For the two last points, see the implementation of socket_import_stream in  
http://lxr.php.net/opengrok/xref/PHP_TRUNK/ext/sockets/sockets.c#2434
It would be a good idea to do some refactoring and share code between the  
two functions.

* (remark) "For IPC", the vast majority of use cases would be already  
covered by php://fd; you would this this only for socket specific  
functionality.


-- 
Gustavo Lopes

---

## #52445 — Florian Wilkemeyer — 2011-05-18T11:27:14+00:00

URL: https://externals.io/message/52443#52445 · In reply to: #52444

Am 18.05.2011 13:13, schrieb Gustavo Lopes:
> Em Wed, 18 May 2011 11:44:35 +0100, Florian Wilkemeyer <fw@f-ws.de> 
> escreveu:
>
> > […]
>
> I can commit this, but a few changes are required first:
>
> * This doesn't work on Windows, so it should be ifdef'd out on that 
> platform.
> * The family can be detected
> * The blocking behavior should be queried, not hardcoded to 1
> * This patch is not up-to-date with trunk/5.4 (see php_create_socket)
>
> For the two last points, see the implementation of 
> socket_import_stream in 
> http://lxr.php.net/opengrok/xref/PHP_TRUNK/ext/sockets/sockets.c#2434
> It would be a good idea to do some refactoring and share code between 
> the two functions.
>
> * (remark) "For IPC", the vast majority of use cases would be already 
> covered by php://fd; you would this this only for socket specific 
> functionality.
>
>
Okay,


#1 it's already
#2 & 3 no problem
#4 i'll checkout 5_4 today and port it to the version / see what can be 
shared

i'll resubmit the fixed / changed patch, when i've applied the changes


Thanks,
Florian
