1

I want to accomplish the following behavior in php:

1 - Script gets called with parameters

2- I Intiate a thread for a long running operation

3 - Script should return control to the caller

4- Thread executes till its finished

Is this behavior possible? What i am seeing now, is that the script wont return until the thread has finished executing, which makes sense as the execution of the thread would probably die if the script stops executing , but is there no way to stop blocking the client so they can go on about their business? Am i stuck using some exec() call to get this behavior? Is there a way to get this done with threading only? Id like to avoid using exec if possible..

So if someone calls my script from a browser, it should just return immidiatly, and the long running process should keep executing until its done.

Thanks

Daniel

Daniel
  • 22,363
  • 9
  • 64
  • 71
  • Possible duplicate: http://stackoverflow.com/questions/138374/close-a-connection-early http://stackoverflow.com/questions/16294106/continue-php-script-after-connection-close – Pedro Gimeno Nov 26 '14 at 18:53

1 Answers1

0

Yes, its possible. Call your php script via AJAX, and and create multiple instances of the ajax function dynamically. See attached screenshot. When I compared results of running a single function versus 24 instances, my data was processed about 15x faster. I am trying to populate a MySQL table with about 30 million records, and each record involves calculating distance in miles from city center, based on lat/lng. So yes, its no walk in the park. As you can see, I am averaging about See this:

multi threads http://gaysugardaddyfinder.com/screen2.PNG multi threads http://gaysugardaddyfinder.com/screen.png

This may be a glorious hack or what not - but it sure worked great for me.

My server is a Xeon 72 Core setup with 64 GB RAM.

Gautam Sharma
  • 204
  • 1
  • 3
  • 11