B
B
bears2017-11-06 07:07:43
PHP
bears, 2017-11-06 07:07:43

Queue question?

Colleagues, I ask for help on a seemingly very elementary problem. I'm working with queues for the first time, and everything seems to be working as it should, but there is a problem with the data. The essence of the question is that Gearman is installed, there is one function in the worker, it receives an array of words from the client, these words should be checked in another array (a total array of phrases, about a million) (now it gets from csv) and so, if at least one is found in this array word, then this element of the array must be removed so that it no longer participates in other tasks. The simplest example:

// Client

$client = new \GearmanClient();
$client->addServer();

$results = new \StdClass();
$results->value = [];

for ($i = 0; $i < 1000; $i++) {
    $words = []; // вот тут рандомное количество слов

    $client->addTaskHigh("find", json_encode($words), $results, $i);
}

$client->runTasks();




// Worker

$worker= new GearmanWorker(); 
$worker->addServer(); 

$phrases = // массив, данные берутся из csv файла

$worker->addFunction("find", "findPhrases", $phrases);

while ($worker->work());

function findPhrases($job, &$phrases) {
    $words = json_decode($job->workload(), true); // слова, полученные от клиента

    // вот тут то и надо удалить в массиве $phrases все элементы, в которых найдены слова из массива $words
}

The problem is that I run the worker, for example, 5 times through the supervisor, and each worker must have an actual array with phrases. So far, there is only one idea - to store an array of phrases in memcached / redis, but I still don’t know how to make sure that the data there is up-to-date, why not do cyclic requests? One task runs for 30-90 seconds.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question