> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Running PHP scripts from cron jobs

> Run PHP scripts from cron jobs effortlessly with our concise guide, complete with code snippets and tips.

This article describes how to run PHP scripts from cron jobs.

## Running PHP scripts from cron jobs

A common method for running PHP scripts from a cron job is to use a command-line program such as **curl** or **wget**. For example, the cron job runs a command similar to the following command:

```bash theme={null}
curl http://example.com/script.php
```

In this command, **curl** retrieves the web page, which then runs the PHP script.

However, there is a better way to run PHP scripts on your web site from cron jobs. You can run the script directly by using the PHP command-line interpreter. This method is just as effective, and usually faster. The following command shows how to run a script using the PHP command-line interpreter:

```bash theme={null}
/usr/local/bin/php -q ${HOME}/public_html/script.php
```

In this example, the PHP command-line interpreter runs the *script.php* file in the user's *public\_html* directory. The **-q** option enables quiet mode, which prevents HTTP headers from being displayed.

Depending on the code in your PHP script, it may only run correctly when called from a specific directory. For example, if the script uses relative paths to include files, it will only run if it is called from the correct directory. The following command shows how to call a PHP script from a specific directory:

```bash theme={null}
cd ${HOME}/public_html/; /usr/local/bin/php -q script.php
```

<Note>
  If your script requires special configuration options, you can use a custom *php.ini* file. The **-c** option allows you to call a PHP script using a custom *php.ini* file:

  ```bash theme={null}
  /usr/local/bin/php -c ${HOME}/php.ini ${HOME}/public_html/script.php
  ```
</Note>

## More information

For information about how to use cPanel to create a cron job, please see [this article](/docs/cron-jobs).

## Related articles

* [Custom php.ini files](/docs/custom-php-ini-files)

* [PHP include paths](/docs/php-include-paths)
