I
I
incontumaciam2015-09-22 01:30:09
PHP
incontumaciam, 2015-09-22 01:30:09

PHP how to parallelize requests?

There is an Apache + PHP + MySQL server. There is
a store.php script on it that receives GET data and writes to the database at a frequency of 5-10 times per second. Also on this VirtualHost there are "long" scripts that can work for more than a minute (file_get_contents () - reading data from rest / api from someone else's service).
It turns out that "long" scripts block the main thread and the data that should be entered into the database will become queued.
But for monitoring, I need the data to be entered into the database as soon as it is sent (with a slight delay).
How to make "long" requests that are just waiting for a response not take up the process? If I move them to a new VirtualHost, will they have their own php process? What can be done within one VirtualHost?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
AlikDex, 2015-09-22
@AlikDex

scripts of one session are blocked
do something like this

<?php
passthru("/usr/bin/php /path/to/script.php ".$argv_parameter." >> /dev/null 2>&1 &");
?>

or replace with exec. The point is to start the process and get rid of it. You can still dig thread's, but he did not come across them.

S
skyfortress, 2015-09-22
@skyfortress

Maybe you should use PHP-FPM?

A
Alex Safonov, 2015-09-22
@elevenelven

You can look towards Gearman .
In short, you create a request in the script to perform certain work and pass it to the worker (who will already be doing it for a minute), and the script itself will spend a second on this. He will give the next job to another free worker.
Very comfortably. Although it requires some investment in infrastructure.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question