Category: PHP

  • Use a cron job to fetch a JSON endpoint in PHP

    by

    in

    A cron job is a scheduled task that runs automatically at specified intervals on a Unix-based operating system. The name “cron” comes from the Greek word “chronos”, which means “time”. Cron is a time-based job scheduler in Unix-like operating systems. Users that set up and maintain software environments use cron to schedule jobs (commands or…

  • WordPress action hook when publishing a post and custom fields

    by

    in

    To create a WordPress hook when publishing a post, you can use the publish_post action hook. This hook is triggered whenever a post is published, or if a post is updated and its status is changed to “published.” Here’s an example of how you can use this hook to create a custom function that runs…

  • Running a function once a day in PHP

    by

    in

    There are a few ways you can run a function once a day in PHP. 1. Use a CRON job A CRON job is a time-based task scheduler in Unix-like operating systems. To set up a CRON job, you will need to have access to the command line and be able to edit the CRON…

  • Fetching a JSON endpoint in PHP

    by

    in

    This example uses the cURL library to execute an HTTP request to the specified URL. The response from the server is stored in the $response variable as a string. The json_decode function is then used to parse the JSON string and convert it into an associative array, which is stored in the $data variable. You…