First I suggest you to reorder your tasks:
- User uploads an image
Upload confirmation is sent to user.
Image is processed
- Other time intensive functions are called
Then you have following options, how to deffer parts 3&4:
Option 1:
Send confirmation to user on step 2, use ignore_user_abort()
and continue with handling image (non optimal, as user will still see "page loading" message.
Option 2: IBP-style.
Do steps 1-2, then add processing job to some sort of database. At random time show image to the users.. Image is actually link to the php script that do ignore_user_abort()
and process your queue of items.
Option 3:
Same as option 2, but don't show image. Instead, you will have to do request to own server with cURL, or similar. Idea is that you start request, and don't wait for it to end, just stop main script execution.
Option 4: start a cron script that starts every 5-15 minutes and do needed tasks. It can also live on background 24h, and sleep for 20 seconds between checking for tasks. This option might be best in case you have relatively busy website.
Option 5: try to do something like exec() or shell_exec() to ruin processing script on background, after you added task to the queue.
Examples of how to do options 2 & 3:
Asynchronous PHP calls?
How do I make an asynchronous GET request in PHP?