- How do I install spatie/ping in a Laravel application?
- Install it with composer require spatie/ping. The package is framework-agnostic and does not ship a Laravel service provider, facade, or config file, so you wire it into Laravel yourself. A thin adapter bound in a service provider is the cleanest way to use it from Artisan commands, jobs, or diagnostic services.
- Does spatie/ping support Laravel out of the box?
- No. spatie/ping is a small PHP wrapper around the system ping command, not a Laravel package in the conventional sense. It has no service provider, config publishing, facade, or Laravel-specific integration. Your application must own the Laravel binding, configuration, validation, and result handling.
- How do I run a ping and get packet loss and timing results with spatie/ping?
- Create a Ping instance with a hostname and call run, which returns a Spatie\Ping\PingResult. The result exposes isSuccess, hasError, error, packetsTransmitted, packetsReceived, packetLossPercentage, minimumTimeInMs, maximumTimeInMs, averageTimeInMs, standardDeviationTimeInMs, and individual lines. You can also serialize results with toArray and rebuild them with fromArray for logging or queue payloads.
- Can I use spatie/ping in a Laravel queued job or scheduled task?
- Yes, but the package is synchronous and blocking, so it is a better fit for queued jobs, Artisan commands, or scheduled health checks than user-facing HTTP request paths. Keep the probe behind an internal interface and return normalized DTOs or arrays to the rest of the application. Avoid leaking raw ping output into product logic.
- What are the production requirements for running spatie/ping?
- The runtime must have the ping binary available and permitted, outbound ICMP and DNS must work, and the hosting security policy must allow process execution. Behavior depends on the host OS, ping implementation, locale, flags, and permissions. The package shows Linux and macOS handling, including a macOS fix for IPv4 and IPv6 flags, but Windows support is not evidenced.
- Is spatie/ping safe for pinging user-supplied hostnames?
- Do not pass unsanitized user input as a hostname because the package shells out to the system ping command and that creates command-injection exposure. Validate and allowlist targets, restrict who can trigger probes, and have security review hostname handling and shell execution. Treat the package as an internal infrastructure adapter, not a public endpoint.
- Which Laravel and PHP versions does spatie/ping support?
- The package does not advertise a Laravel version because it is framework-agnostic and does not depend on Laravel. Check its Composer PHP constraints against your application matrix before adopting it. The changelog shows PHP 8.5 CI coverage and Symfony 8 support, but you should still verify your production PHP, Laravel, and base image combination.
- How do I test Laravel code that uses spatie/ping?
- Put spatie/ping behind an internal interface such as PingProbe or HostReachabilityChecker, then mock that interface in unit tests. You can also build PingResult objects with fromArray to test success, error, packet-loss, and timing paths without running ping. Keep a few integration tests against known hosts to compare parsed results with raw output across your target OS matrix.
- What are the limitations of spatie/ping compared with dedicated monitoring tools?
- spatie/ping is a narrow diagnostic wrapper that parses the system ping output; it is not an observability platform, alerting system, dashboard, or historical monitoring store. It is best for scheduled reachability checks, admin tooling, support diagnostics, and embedded network probes, not high-frequency synthetic monitoring. Adoption evidence is thin with 94 stars and 0 dependents, so field validation is limited despite Spatie's reputation.
- How should I handle errors and inconclusive ping results in Laravel with spatie/ping?
- Use hasError and error to inspect the error enum, and use isSuccess for the basic reachability decision. Define a clear fallback policy for inconclusive results, distinguishing unknown from down rather than treating every failure as an outage. Add timeouts, retries, careful logging of raw output, and a normalized result object before using the probe for customer-facing status or alerting.