Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

uniqueginun's avatar

Best solution to a process that takes some time

Hello,

I have a controller method that perform multiple tasks. everything is working fine but one of those tasks takes more time than the others and it slows down the response. so I'm thinking about changing the approach.

the flow of tasks is this:

1- method that perform database insert and return eloquent model

2- another method that insert relationship for that model

3- the task that takes time which is basically calling a stored procedure in oracle database and perform many queries and return unique long integer number

4- update the model by that big number returned from procedure

5- do some file uploading

so what is the best way to do task no #3:

- laravel scheduled cron job

-laravel queues

if they are not the same thing

0 likes
6 replies
CorvS's avatar

@uniqueginun Are your tasks required for the response of your request or is it okay if you dispatch a job that handles the tasks asynchronously?

uniqueginun's avatar

I must notify the user that the request is completed successfully and give him that number generated by the database procedure but I think I can show the success message first and then when the job done I SMS him the generated number??!!

CorvS's avatar

@uniqueginun That would be one possibility. It depends on your case, if it makes sense or not. How long does the task take anyway? Maybe it's okay to let the user wait while the request is being processed and show a loading indicator.

uniqueginun's avatar

I measured it and in worst cast it takes about 6 seconds!! what you think?

CorvS's avatar

@uniqueginun That's absolutely okay I'd say. It's a bigger inconvenience for the user to check his phone for a SMS imo and maybe even having to type the code/number by hand, because its required for the next step or whatever. Just add some entertaining loading indicator.

My suggestion depends on the use case obviously, if the user needs that number/code on his phone anyway, go with a queue job.

martinbean's avatar

@uniqueginun This is a perfect candidate for a queue job. You have a process, that you want to happen once, but can take some time, so put it on a queue and let a worker work through it.

Please or to participate in this conversation.