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

andyandy's avatar

Don't wait for PHP function to finish execution

AJAX calls a script which could return answer almost immediately, but it hangs for 700-500ms (depends) on updating relevant statistics etc. Could I just trigger function with these statistics and not wait for execution to finish and answer AJAX right away?

I would do it as queue job. But it's manager VPS without SSH. I can't install a supervisor to make queue jobs work as I usually do.

0 likes
3 replies
MichalOravec's avatar

Add spinner, or show a prepared message after click on the button.

Snapey's avatar

can you run cron? You can use cron to service your queue.

martinbean's avatar

@andyandy Have a cronjob that does the statistics crunching how often you need it to, and put the results into a cache when it’s done. Then have your AJAX endpoint read the results from the cache; it should have the most up-to-date statistics and return a response pretty quickly.

Please or to participate in this conversation.