-2

I made a php script to load some data to a serial device, this operation take some seconds (10/15). This is not a problem for the requester, the http request take a while to come back like all heavy pages.

My problem is that this script hold all other requests to that Apache/Php web server.

Is this any way to do something in php asynchonously or to configure php (or apache) to manage it not queuing all other requests? Now my apache and php configuration is the standard production configuration.

Tobia
  • 9,165
  • 28
  • 114
  • 219
  • What is the information? Are you reading or writing from the device? Would it be possibly to write a small daemon that continually reads from the device, and publishes it somewhere that the PHP script could quickly read the (most recent) result from? – Jonathon Reinhart May 09 '14 at 06:48
  • Yes, can be, but I would like to know if there is some way to write a "thread job" in php to run asyncronously or at least to not hold all other request to that server. – Tobia May 09 '14 at 06:51
  • Something is wrong with your webserver (not PHP) configuration if one long page request is blocking all others. – Jonathon Reinhart May 09 '14 at 06:53
  • Agree with @JonathonReinhart , posted answer to your question still however. – Zander Rootman May 09 '14 at 06:55

1 Answers1

0

Typically, PHP wasn't made for Asynchronism.. If you want a Async solution, you should maybe take a look at NodeJS.

However, there are quite a number of PHP libraries, that allow you to mimic this sort of behaviour, however, I can't promise what kind of overhead you will experience, or how reliable these libraries are.

To answer your question more directly: You can't configure Apache and PHP to handle (or mimic) it's request Asynchronously. You will need to do it programatically.

Article one (Threading, this is not Async): PHP threading call to a php function asynchronously

Article Two (Segment IO): https://segment.io/blog/how-to-make-async-requests-in-php/

And an example Lib (React PHP): http://reactphp.org/

You're heading down a dark path my friend. PHP was not made for this. One of the many reasons why PHP is dying.

Community
  • 1
  • 1
Zander Rootman
  • 2,178
  • 2
  • 17
  • 29