spatie/ping
Run ICMP pings from PHP and get structured results instead of raw output. Spatie's package wraps the system ping command and exposes packet loss, response times, connectivity status, and individual ping lines as clean, readable objects.
ping output into a typed PingResult (packet loss %, packets sent/received, min/max/avg/stddev latency, per-line timings, error enum). That parsing is the tedious, fragile part — buying it as an MIT dependency is cheaper than owning a parser.$result->toArray() (JSON column or metrics table), render latency and packet-loss trends. The array/serialization + fromArray() round-trip makes persistence and replay straightforward.count, timeoutInSeconds, intervalInSeconds, packetSizeInBytes, ttl, and ipVersion (IPv4/IPv6/auto), then surface a human-readable diagnosis instead of a support ticket.Adopt when:
ping binary is present in the runtime image.PingError enum) rather than scraping stdout in application code.NetworkProbe interface.Look elsewhere when:
-4/-6 flags are skipped on macOS; showLostPackets is Linux-only). Windows ping output differs materially.blackbox_exporter, Uptime Kuma, Zabbix, or a hosted service (Pingdom/Better Stack) will be cheaper to operate than building scheduling, storage, and alerting around this.CAP_NET_RAW/setuid or unprivileged ICMP). This is the most common blocker in hardened containers.ping builds are a real risk.Adoption checklist: pin the version, add a wrapper interface with a fake implementation for tests (real pings are skipped in CI upstream, so our own contract tests matter), validate/whitelist hostnames before they reach the process invocation, and confirm the container image ships ping with the right permissions.
To executives: This is a tiny, free (MIT), actively maintained dependency from a well-known PHP vendor that lets us ship network-visibility features — "is this host reachable, how lossy, how fast" — in days rather than weeks. Cost is one Composer package and a small integration; the risk is bounded because it sits behind our own interface and can be replaced with a few hundred lines of code if we ever need to. It is not a monitoring platform and shouldn't be positioned as one — it's a building block for diagnostics and support tooling.
To engineering: It wraps the system ping and returns a typed PingResult: success/error enum, packet counts and loss percentage, min/max/avg/standard-deviation timings, per-line results, raw output, and toArray()/fromArray() for persistence. Fluent configuration for timeout, count, interval, packet size, TTL, lost-packet reporting, and IPv4/IPv6/auto. Spatie-maintained, active releases through 1.2.x, PHP 8.5 and Symfony 8 in CI. Caveats we should design around: it shells out, is Linux/macOS-focused, requires the ping binary and appropriate socket permissions, and its parsing is only as stable as the underlying iputils output — so we pin the version, validate hostnames, run it from queued jobs, and keep a thin adapter so swapping in a custom parser is a one-file change.
How can I help you explore Laravel packages today?