Calling API every 24hr period with PHP

Viewed 258

I have my API call that retrieves the information I need to pull data onto my site

However, the API call needs to be called every 24hrs but I cannot use cron

Does anyone have an idea on how I can maybe do this with PHP or perhaps JS?

Here's my (simplified) call:

$postdata = http_build_query(
    array(
    'username' => 'user',
    'password'=>'pass'
));

/* API URL */
$url = ' *my_api_url_here* ';
  
$ch = curl_init($url);
  
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
echo json_encode($result);

curl_close($ch);
1 Answers

the best way for calling a code in the specific period times, is the cron job that created for this work

if you use shared hostings platforms such as DA or cPanel or anything else, you can use their cronjob system

Working with cron jobs in DirectAdmin = based on youtube search

Working with cron jobs in cPanel = based on youtube search

Working with cron jobs in Webmin = based on youtube search

How to setup scheduled tasks in Plesk = based on youtube search

and if you not, the best solution for cron job in linux based operating systems, is crontab

Managing Cron Jobs in PHP with Crontab = based on google search

Related