Network
23 entries
checkdnsrr
Checks whether a host has DNS records of a given type (A/MX/NS/TXT, ...), returning true when found — the existence check of the DNS trio.
dns_get_record
Fetches DNS records (A/MX/NS/SOA, ...) for a hostname and returns the record array.
fsockopen
Low-level TCP/Unix socket client: returns a stream resource on success (fwrite/fgets/fclose apply) or false with errno/errstr filled on failure.
get_headers
Sends a request to a URL and returns the response headers as an array (the first element is the status line) — the built-in lightweight HTTP probe.
gethostbyname
Resolves a hostname to its IPv4 address string; on failure it raises no error and returns the hostname unchanged.
gethostname
Gets the local host name: CI and local machines necessarily differ, so the deterministic strategy prints only derived facts (success + non-empty), never the name itself.
getmxrr
Queries a host's MX mail-exchange records, filling the hosts and weights arrays by reference.
getprotobyname / getprotobynumber / getservbyname / getservbynumber
Protocol/service-name queries: forward and reverse lookups into the /etc/protocols and /etc/services system tables (decades-stable IANA values like tcp=6 and http=80/tcp); unknown names return false. getservbynumber is missing in some PHP builds (see notes).
header
Sends a raw HTTP response header: with setcookie and http_response_code it completes the web response control trio; must be called before any output, and is a silent no-op under CLI where headers_list() is always empty.
http_build_query
Serializes an array (nested ones included) into a URL-encoded query string, the inverse of parse_str; spaces are encoded as + by default.
http_get_last_response_headers
Returns the indexed array of headers from the most recent HTTP-wrapper response (first entry is the "HTTP/1.1 200 OK" status line), or null if there were none. Added in PHP >= 8.4.0 as the replacement for the implicit $http_response_header variable deprecated since 8.4. Under CLI no HTTP request has ever been made, so it is always null - an honest environment-independent demo.
http_response_code
Sets or gets the HTTP response status code; under CLI getting returns false and setting is a no-op (the same Web/CLI SAPI split as setcookie).
inet_ntop / inet_pton
IP text/binary conversion: inet_pton packs (4 bytes for IPv4, 16 for IPv6) and inet_ntop expands back - while ip2long is IPv4-only, this pair covers both stacks; invalid input returns false.
ip2long / long2ip
Converts a dotted-decimal IPv4 string to a 32-bit unsigned integer and back (ip2long to int, long2ip to string).
parse_str
Parses a URL query string into an array (the second argument is mandatory since PHP 8.0); dots and spaces in keys are converted to underscores.
parse_url
Parses a URL and returns its components.
pfsockopen
Persistent sockets: identical signature to fsockopen, the only difference being connection lifetime — after closing, the handle returns to a process-level persistent pool for same-process reuse (scope decided by the SAPI; on CLI the pool dies with the process); failures return false with errno/errstr filled.
Io\Poll
New in PHP 8.6: epoll/kqueue/event-ports/WSAPoll-grade I/O multiplexing — breaks past stream_select's 1024-descriptor ceiling and returns readiness as Watcher objects; wait takes a Time\Duration outright.
rawurldecode
Decodes a percent-encoded string, keeping plus signs (+) literal.
stream_context_create
Creates a stream context — the foundation for advanced file_get_contents/fopen network usage: preset HTTP method, headers, timeout, user-agent and more in a ['wrapper']['option'] nested array, which every stream call taking $context then inherits.
stream_select
I/O multiplexing — the direct descendant of C select(2): watches the read/write/except stream sets until any become ready or the timeout expires; returns the number of ready streams (0 = timeout, false = error, so test with === false), and rewrites the three arrays in place into the ready subset.
syslog
Sends a message to the system logger (LOG_INFO-style priority constants combined with the openlog facility); always returns true, the destination is up to syslog.conf/journald, and sending never crashes under CLI.
URI Builders
The PHP 8.6 URI builder family: UriBuilder stores only overrides and build() rebases onto an existing URI — completing the parse↔build pair with parse_url/http_build_query; the coexistence of RFC 3986 and WHATWG is the teaching core.