Network

23 entries

checkdnsrr Function 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 Function Fetches DNS records (A/MX/NS/SOA, ...) for a hostname and returns the record array. fsockopen Function 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 Function 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 Function Resolves a hostname to its IPv4 address string; on failure it raises no error and returns the hostname unchanged. gethostname Function 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 Function Queries a host's MX mail-exchange records, filling the hosts and weights arrays by reference. getprotobyname / getprotobynumber / getservbyname / getservbynumber Function 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 Function 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 Function 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 Function 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 Function 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 Function 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 Function Converts a dotted-decimal IPv4 string to a 32-bit unsigned integer and back (ip2long to int, long2ip to string). parse_str Function 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 Function Parses a URL and returns its components. pfsockopen Function 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 Function 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 Function Decodes a percent-encoded string, keeping plus signs (+) literal. stream_context_create Function 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 Function 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 Function 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 Function 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.