1

The scenario is: when a user upload a image, we do image resizing on the server, but instead of waiting for this job done, I want it to response to the user immediately. if there is a thread available, I would properly just use thread to do this task, but as far as I know , there is no thread in php, so how can I achieve this goal? Thanks for ideas and suggestions.

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
bingjie2680
  • 7,643
  • 8
  • 45
  • 72
  • possible duplicate of [php execute a background process](http://stackoverflow.com/questions/45953/php-execute-a-background-process) – Gordon Jul 27 '11 at 09:12

3 Answers3

5

Either fork the process (ugly and unreliable) or use a JobQueue, like Gearman.

Gordon
  • 312,688
  • 75
  • 539
  • 559
2

Use a PHP script to do all this processing, and call it on shell using shell_exec. So the script would run seperately, and your code would bypass this operation by running it in the shell instead of the main code. See my answer here for similar kind of task :

PHP API acess multiple calls

Community
  • 1
  • 1
DhruvPathak
  • 42,059
  • 16
  • 116
  • 175
1

Forking is not reliable, if your server crashes for some reason, the resizing will never happen.

Put a job in a queue, and use a cron job to do this. There are many ways of creating a job queue, you can write your own using a database or use an existing solution.

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176