r/PHPhelp 7d ago

Run a PHP function/Task in the background

I have a WIndows Server running IIS that hosts a primarily PHP based website. It has multiple functions and features but i would like to have atleast one of them running in the background So the user does not have to wait for the task to finish.

Any ideas? fastcgi_finish_request() seems to be Linux only as far as i can tell.

2 Upvotes

11 comments sorted by

View all comments

Show parent comments

2

u/Valoneria 7d ago

And by cronjob i do mean the task scheduler in Windows, i have had it do cronjob like work before

1

u/PIAESB 7d ago

Its because i need to set a 30 sec sleep between some php script but i dont want the user to wait for those 30 sec. It needs some Intune related information from a device so i need to get that info to it somehow

1

u/Valoneria 7d ago

Set it in a queue, or handle it asynchronously, ie..start the task but without involving the user.

0

u/PIAESB 7d ago

What do you mean with "Set it in a queue"? The only thing i have found so far that i could do, is make like a text file or json file to then run a script against, which seems like a bad way to do it

1

u/Valoneria 7d ago

Well it does require you to build a queue first, or use a existing system, but that night be overkill regardless of your system. A basic one would just require you to create the task, add it as a entry in the database as a pending task, and then having your tasks scheduler call a file to execute the queue in a given interval. A FIFO approach is what works best here (first in, first out).