Answer the question
In order to leave comments, you need to log in
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
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question