0

I am wondering if I can do some threaded work on PHP side, just like in Java...

I have tried sleep() function, but it seems it stuck all processes on the server.

I wanted to process several post actions, before one is complete.

But when I tried with Ajax, I noticed that although I sent asynchronous requests, they got proceeded one by one, in sequence.

Is there any way to create a thread on PHP side?

kapa
  • 77,694
  • 21
  • 158
  • 175
Codemole
  • 3,069
  • 5
  • 25
  • 41

4 Answers4

1

Try a job server: http://gearman.org/

KingCrunch
  • 128,817
  • 21
  • 151
  • 173
1

PHP does not support multithreading (in scripts) or asynchronous processing.

However, if you send multiple requests to your server they will be processed in parallel as long as your server is not configured to handle only one request at a time.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
1

PHP does not support multithreading. Also this link can be useful

Community
  • 1
  • 1
Leri
  • 12,367
  • 7
  • 43
  • 60
0

We sometimes used a hack. We created one script and inside it we sent several http requests without waiting for a response.

That way we were able to mimic threads.

Songo
  • 5,618
  • 8
  • 58
  • 96