What is the code to call a cron job from php?

1.5k views Asked by At

I would like to call a cron job from within a PHP script. I am assuming this is the correct and most efficient solution to my problem.

Background:

I want to run a script that uses a user's inputted password before I store it in the database with 1 way encryption.

I also want to make sure the entire script runs even if the user leaves my site.

There are either two possibilities.
1.) Create a two way encrypted password that I can run later in the evening through cron (probably not secure, but any suggestions would be appreciated).

2.) Create a cron job on the fly using PHP to use the user's password before I store it in 1 way encryption.

Assuming #1 is not possible (or not secure), how would I call a cron job on the fly using php? If this isn't the only solution, how can i run a PHP file that will finish running if the user leaves my page?

1

There are 1 answers

1
Daniel On BEST ANSWER

You don't want to start a CRON job, but a background command. Execute a shell from PHP, and pass it a command like this:

bash -c 'mycommand & exit';