How to Run a PHP File in the Background

104 9
    • 1). Log in to the terminal of the server running PHP using an administrative account or the account that owns the PHP file.

    • 2). Find the path to PHP on your system by typing "whereis php" without quotes. You likely will receive a location such as "/usr/bin/php" or "/usr/local/bin/php."

    • 3). Visit the Crontab Code Generator website. The address is included in the Resource link below.

    • 4). Enter the path to PHP followed by the path to the PHP file you would like to run. Enter this in the "Command" text box. For example, enter "/usr/local/bin/php /home/bob/private/prune_database.php" without quotes if your PHP installation is at "/usr/local/bin/php" and your PHP file is at "/home/bob/private/prune_database.php."

    • 5). Choose how often you would like the script to run under the "Minute," "Hour," "Day," "Month," and "Weekday" columns. You can select multiple values or choose to have it execute on every occurrence.

    • 6). Click "Create Crontab Line" to generate a line of text to add to your Crontab.

    • 7). Type "crontab -e" without quotes in the terminal to open the crontab.

    • 8). Copy the text from "Result Crontab Line" and paste it into the terminal window. The crontab program will merge this command into your crontab and activate it. Your script will now run at the designated times.

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.