-5

I want to execute a script based on a condition at a time interval until some other condition is met.

Let me explain more; For example, I have a system for a delivering goods to clients. I'm working on this feature where a client requests goods to be delivered, now after the request has been placed. I want to notify my clients every 5 minutes or 3 times if they would want to cancel their request before its too late.

I'm working with php and I cant seem to find a way to implement this feature, at first I was going to use a cron job but couldn't find a way of executing a cron job in my php script. I don't know if cron jobs could be used in this scenario or not.

I cant seem to find any way of solving this problem.

At first I didn't think through well enough and figured cron jobs could come to my rescue but i just realized I couldn't find any way of calling a cron job from php code, or executing a php script at some interval without consuming too many server resource, or the script timing out.

Is there anyway to solve this issue. Thank you.

marvin ralph
  • 1,100
  • 3
  • 23
  • 43
  • 5
    You don’t call/execute a cron job from a PHP script, it’s the other way around - cron is the mechanism you use to make your PHP script run at specific intervals. – 04FS Mar 29 '19 at 10:32
  • So does your server supports cron jobs, e.g. has installed crontab? If not, you can use some online tools, e.g. https://cron-job.org/en/ – Justinas Mar 29 '19 at 10:33
  • Create a php script which you want to run. If you are using mysql as a database, there is a option to run your script by setting intervals, like once in a day or once in 3 hour etc. – Roshni hegde Mar 29 '19 at 10:37
  • @Roshnihegde Can you please provide more details on this. Thank you. – marvin ralph Mar 29 '19 at 10:54

1 Answers1

1

By using cron job, you just have to wait specific time as you entered then it will automatically execute the script you created.

Example: Customer, order 1 product then he/she added to cart and redirect to payment page and choose bank transfer.

Let say, if you want to check if the client didn't process it's payment request at specified time (5 days) then, the client request will be automatically cancelled request.

You have to configure your cron task. Please refer to this link: Execute PHP script in cron job

Muamar Ali
  • 155
  • 1
  • 9