PHP
Ping Cronping from PHP scripts and applications.
PHP's built-in file_get_contents or cURL extension can be used — no extra packages needed.
Using file_get_contents
<?php
function pingCronping(string $token): void
{
$url = "https://ping.cronping.com/{$token}";
$context = stream_context_create([
'http' => [
'timeout' => 10,
'ignore_errors' => true,
],
]);
try {
@file_get_contents($url, false, $context);
} catch (\Throwable $e) {
error_log("Cronping ping failed: " . $e->getMessage());
// Don't rethrow — the job succeeded, only the notification failed
}
}
// Your job logic
function runBackup(): void
{
// ... your code here ...
}
runBackup();
pingCronping('<token>');Using cURL
More control over timeouts and response handling:
<?php
function pingCronping(string $token): void
{
$url = "https://ping.cronping.com/{$token}";
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_FAILONERROR => false,
]);
$result = curl_exec($ch);
if ($result === false) {
error_log("Cronping ping failed: " . curl_error($ch));
}
curl_close($ch);
}Using Guzzle
If your project already uses Guzzle:
<?php
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
function pingCronping(string $token): void
{
$client = new Client(['timeout' => 10]);
try {
$client->get("https://ping.cronping.com/{$token}");
} catch (GuzzleException $e) {
error_log("Cronping ping failed: " . $e->getMessage());
}
}In a Laravel command
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Http;
class NightlyBackupCommand extends Command
{
protected $signature = 'backup:nightly';
public function handle(): int
{
// ... your job logic ...
try {
Http::timeout(10)->get('https://ping.cronping.com/<token>');
} catch (\Throwable $e) {
logger()->warning('Cronping ping failed', ['error' => $e->getMessage()]);
}
return Command::SUCCESS;
}
}In a Symfony console command
<?php
namespace App\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
#[AsCommand(name: 'app:nightly-backup')]
class NightlyBackupCommand extends Command
{
public function __construct(private readonly HttpClientInterface $httpClient)
{
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
// ... your job logic ...
try {
$this->httpClient->request('GET', 'https://ping.cronping.com/<token>', [
'timeout' => 10,
]);
} catch (\Throwable $e) {
$output->writeln('<comment>Cronping ping failed: ' . $e->getMessage() . '</comment>');
}
return Command::SUCCESS;
}
}