-1

I have a form where I take data as input in a form and sends it as post request now want that it should send a response as soon as the request is received and continue processing data at the background until it is fulfilled. so my question is how can I make this possible with PHP and if yes how I can implement that

  • This could help you: https://stackoverflow.com/questions/21605585/creating-background-processes-in-php-for-long-running-process#21612782 – T K Oct 21 '18 at 19:43
  • Consider adding an example of what you currently have and what you've tried, as well as whats not working. Your question shows no effort in solving the problem yourself. – NikxDa Nov 03 '18 at 00:19

1 Answers1

1

This is possible but it requires some trickery pokery.

PHP is by default a blocking language, which is to say that your browser will wait for all the processing before continuing, which is not what YOU want.

The PHP-in-language solution for this is to use PHP background workers: https://secure.php.net/manual/en/class.worker.php, which may be all you need if you're trying something simple.

If you're building a more complicated application which needs high availability and such, then you may want to look at a more robust solution using message queues. There are a number of technologies available, most ending in the suffix "mq".

E.g. RabbitMQ and IronMQ

Most of these use one of two protocols, the most widely used being AMQP. Generally installation of these libraries is simple but the networking and implementation side can be a bit more complex as they run over particular TCP ports.

The general design structure when using these is that the mq library runs as a service listening on a port, PHP sends a message to the library across that port and then the mq library will spool up a background PHP worker in its own time to process the message. Meanwhile your browser can carry on with other things and potentially be alerted once the change is done if you're using something like websockets or polling.

You can also look into GearMan, which provides a framework for creating PHP workers.

The other route to go is to use a webworker and handle the non-blocking code structure in the browser.

geoidesic
  • 4,649
  • 3
  • 39
  • 59