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 pings in PHP and get structured results. Spatie Ping wraps the system ping command to report success/error status, packets sent/received, loss percentage, min/max/avg response times, and per-reply lines for easy monitoring and diagnostics.

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 root. The package has no Laravel-specific dependencies and works with PHP’s native `shell_exec()` or `proc_open()`. Test your environment after installation to ensure the system ping command is accessible.
What Laravel versions does spatie/ping support?
The package is framework-agnostic but works seamlessly with Laravel 8.x, 9.x, and 10.x. It leverages PHP 8.0+ features and has no Laravel-specific version constraints. Test with your target Laravel version to confirm compatibility.
Can I use this for real-time latency monitoring in a Laravel app?
Yes, but avoid blocking HTTP requests. Wrap `Ping::run()` in a Laravel job (e.g., `PingHealthCheckJob`) and dispatch it from a queue worker or cron job. For real-time decisions, cache results or use Laravel Echo to push updates.
How do I handle cross-platform issues (e.g., macOS vs. Linux ping flags)?
The package auto-detects OS-specific ping flags, but some systems (e.g., macOS) may require adjustments. Test on all target environments. Override defaults via `config('ping.custom_flags')` if needed, or extend the `Ping` class for custom logic.
What’s the best way to store ping results for historical analysis?
Store results in a Laravel migration table (e.g., `ping_results`) with columns for `host`, `timestamp`, `packet_loss`, `avg_rtt`, and `status`. Use Laravel Scout or a time-series DB like InfluxDB for large-scale data. Add a `PingResultObserver` to log results automatically.
How do I trigger alerts when ping failures or high latency occur?
Dispatch Laravel events (e.g., `PingFailed`, `HighLatency`) when thresholds are breached. Use `PingResult::packetLossPercentage() > 20` or `PingResult::averageTimeInMs() > 500`. Subscribe to events in `EventServiceProvider` and send notifications via Laravel Notifications or webhooks.
Is spatie/ping suitable for high-volume ping checks (e.g., 100+ hosts)?
No—system ping calls are blocking. Queue jobs for async execution and limit concurrent checks to avoid system overload. For large-scale monitoring, consider dedicated agents like Telegraf or specialized services (e.g., Pingdom).
How do I mock spatie/ping for unit testing in Laravel?
Use Laravel’s `Mockery` or `Pest` to stub `shell_exec()`. Example: `Mock::shouldReceive('exec')->once()->andReturn('PING output...');`. Test `PingResult` methods like `isSuccess()` or `packetLossPercentage()` against mocked responses.
Can I integrate this with Laravel Horizon for scheduled ping checks?
Yes. Create a `PingHealthCheckJob` and schedule it in `app/Console/Kernel.php` under `schedule()`. Use Horizon’s dashboard to monitor job progress and failures. Example: `$schedule->job(new PingHealthCheckJob)->everyMinute();`
What are the alternatives to spatie/ping for Laravel network monitoring?
For lightweight checks, consider `spatie/ping` or PHP’s `fsockopen()` for TCP checks. For production-grade monitoring, use dedicated tools like New Relic, Datadog, or Telegraf. If you need ICMP-specific features, `spatie/ping` is the most Laravel-friendly option.
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata