Answer the question
In order to leave comments, you need to log in
Once again about the asynchronous function call in php?
I want to call a function while the script is running so that the script doesn't have to wait for it to complete:
$html = curl_multi_getcontent($curl); // вот тут я получаю результат операции
$info = curl_getinfo($curl); // вот тут - информацию об операции
process_resault($html, $info); // ВОТ ЭТА ФУНКЦИЯ будет работать минут десять, обработает результат, запишет его в базу, я НЕ ХОЧУ ЖДАТЬ ЕЁ ЗАВЕРШЕНИЯ
// Здесь я продолжаю работать, добавляю новые урлы в мультикурл, жду новых результатов и т.п.
Answer the question
In order to leave comments, you need to log in
Use the task queue (at least ready-made, at least your own). It will be much easier to come up with crutches and cross-platform.
We use Jenkins, with the help of curl we pull the task with parameters, and it continues to work. Jenkins has logs, he monitors the queues.
In general, you need to run this function in a separate process / thread, only then it will be executed independently (with the usual caveats, but still).
How exactly to do this is the question. The suggestion above is to keep separate processes that will pick up the job from the queue. There is also a standard pcntl extension that implements the standard unix fork mechanism for creating a child process, but it does not work on Windows, for example, due to the fact that it is organized differently there.
Additionally, there are features with the work of php in the web server with set_time_limit ().
When I had to do some long tasks, I actually made a daemon in bg and worked with it through different interfaces - either a queue through the database, or REST, which is cooler.
There is lib_events in php, but I didn’t deal with it and I can be mistaken in its purpose for your task.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question