G
G
germn2012-06-23 15:54:22
PHP
germn, 2012-06-23 15:54:22

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); // ВОТ ЭТА ФУНКЦИЯ будет работать минут десять, обработает результат, запишет его в базу, я НЕ ХОЧУ ЖДАТЬ ЕЁ ЗАВЕРШЕНИЯ

// Здесь я продолжаю работать, добавляю новые урлы в мультикурл, жду новых результатов и т.п.

Those. the task is to call an arbitrary function with parameters and, without waiting for its completion, continue working.
First of all, the cross-platform solution interests.
I know that there were articles on the topic, but I did not find the answer to my question. Don't drink too much.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

6 answer(s)
D
DevMan, 2012-06-23
@germn

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.

A
Alexander Lozovyuk, 2012-06-23
@aleks_raiden

For example, gearman

K
kuzemchik, 2012-06-23
@kuzemchik

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.

W
Wott, 2012-06-23
@Wott

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.

A
Andrey Shiryaev, 2012-06-24
@Claud

There is lib_events in php, but I didn’t deal with it and I can be mistaken in its purpose for your task.

E
EugeneOZ, 2012-06-24
@EugeneOZ

Here is my php library for creating deferred tasks:
github.com/jamm/Tasks . Requires nothing but PHP. Can store in memory if desired (Redis, Memcached, APC).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question