Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ping Laravel Package

spatie/ping

Run ICMP ping from PHP and get structured results. Spatie Ping wraps the system ping command, parsing packet loss, transmit/receive counts, min/max/avg times, standard deviation, per-line responses, and error status for quick connectivity checks.

View on GitHub
Deep Wiki
Context7

Run an ICMP ping and get structured results

Frequently asked questions about Ping
How do I install spatie/ping in a Laravel project?
Run `composer require spatie/ping` in your project directory. The package has no Laravel-specific dependencies and works with PHP 8.1+. No additional configuration is needed for basic usage.
Can I use this package to monitor external APIs or services?
Yes, but ICMP may not be ideal for APIs behind firewalls. For HTTP/HTTPS endpoints, consider combining this with HTTP checks (e.g., Guzzle) or use a hybrid approach with fallback logic. ICMP is better suited for raw network diagnostics.
How do I handle errors or retries if a ping fails?
The package doesn’t include built-in retry logic. Use Laravel’s retry helper (e.g., `try-catch` with `retry()`) or wrap the ping in a Laravel Job with `spatie/queueable-model` for async retries. Circuit breakers must be implemented manually.
Does spatie/ping work on Windows in production?
Windows requires admin privileges for ICMP. For production, use Docker with a Linux container or restrict usage to Linux/macOS hosts. Test thoroughly in staging to avoid permission issues.
How can I integrate ping results into Laravel monitoring tools?
Use the structured `PingResult` object to log metrics (e.g., `packetLossPercentage()`, `averageTimeInMs()`) via `spatie/laravel-logging` for ELK or export to Prometheus with `spatie/laravel-prometheus`. For alerts, pipe results to `spatie/laravel-monitor`.
What Laravel versions does spatie/ping support?
The package supports PHP 8.1+ and works with Laravel 9+. For older Laravel versions (e.g., 8.x), ensure your PHP version is compatible. No Laravel-specific features are required.
How do I test spatie/ping in a CI/CD pipeline?
Unit testing ICMP is challenging due to system call dependencies. Use integration tests in staging/production or mock the `Ping` class in unit tests. Test edge cases like packet loss, high latency, and error responses.
Is there a way to run multiple pings concurrently?
No, the package runs pings sequentially. For concurrent checks, dispatch pings as Laravel Jobs with `spatie/queueable-model` or use a sidecar service (e.g., Redis Queue). Avoid aggressive pinging (>10/sec) to prevent network throttling.
What alternatives exist if ICMP is blocked by firewalls?
Fallback to TCP-based checks (e.g., HTTP HEAD requests with Guzzle) or DNS resolution (e.g., `dns_get_record()`). For hybrid monitoring, create a wrapper class that tries ICMP first, then falls back to HTTP if ICMP fails.
How accurate are the latency measurements compared to native `ping` commands?
The package mirrors system `ping` output but may have slight variations due to PHP process overhead. For critical latency monitoring, cross-validate with native tools (e.g., `ping -c 4`) or use TCP-based alternatives for sub-millisecond precision.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai