In the PHP framework Laravel within production environments, workers and supervisors ensure that the jobs stored in, for example, Redis are processed. If you want to be completely independent of this on localhost, you can either use the sync driver to always execute the jobs immediately. This has the disadvantage that the current PHP process is blocked and the request hangs until the job has been processed.
It is better to call another PHP instance that initiates a one-time worker pass. The following implementation also takes care of Windows / Mac / Linux differences. We first define a job in the usual way:
Then we create a general helper that takes care of the execution:
Finally, we call this function in a controller: