This is an old revision of the document!
PHP RFC: Implement socket_getaddrinfo()
- Version: 0.1
- Date: 2016-08-08
- Author: David Walker (firstname.lastname@example.org)
- Status: Under Discussion
- First Published at: http://wiki.php.net/rfc/socket_getaddrinfo
This RFC targets a reported feature request in #72733. The request is that PHP expose the C level function getaddrinfo(). This is a missing nice piece to the current socket library. When dealing with variable networks it would be beneficial to allow libc to tell us what methods of connecting/listening would be most appropriate given a set of hints.
The implementation I'm proposing implements 4 new functions.
socket_addrinfo_lookup() will return an array of resources, with each resource corresponding to each returned addrinfo. The next two implemented methods
socket_addrinfo_connect(), would be used to bind, or connect, to a given resource rather than make the user go through the process of creating the socket and connect/binding themselves. The last is to convert the resource to an array for examination.
socket_addrinfo_lookup(string node[, mixed service, array hints]) : array socket_addrinfo_connect(resource $addrinfo) : resource socket_addrinfo_bind(resource $addrinfo) : resource socket_addrinfo_explain(resource $addrinfo) : array
<?php $addrinfo = socket_addrinfo_lookup('127.0.0.1', 2000, array('ai_family' => AI_INET, 'ai_socktype' => SOCK_STREAM)); $sockaddr = reset($addrinfo); if (!$sockaddr) die ("No Valid Socket Types"); $sock = socket_addrinfo_bind($sockaddr); // ^^ $sock is a socket resource that is bound to 127.0.0.1:2000 using TCP/IP ready for reading
Backward Incompatible Changes
New functionality; no BC issues.
Proposed PHP Version(s)
Next PHP 7.x (currently 7.2)
To Existing Extensions
Socket acquired new functionality
Exposing the AI_* family of constants.
Proposed Voting Choices
Vote to implement the new functions, would require a 2/3 majority.