Worker Gearman from Cli Console to Php / ~#root -i Worker Gearman from Cli Console to Php / ~#root -i Worker Gearman from Cli Console to Php / ~#root -i Worker Gearman from Cli Console to Php / ~#root -i Worker Gearman from Cli Console to Php / ~#root -i Worker Gearman from Cli Console to Php / ~#root -i Worker Gearman from Cli Console to Php / ~#root -i Worker Gearman from Cli Console to Php / ~#root -i
  • RU
  • UA
  • EN
  • Create an online store
  • Documentation
  • Blog
    • Unix ОS
    • Php
    • MySQL
    • JavaScript
    • Package Managers
    • Docker
    • Seo
  • Auxiliary services
    • Short Links
    • Exchange views YouTube
  • Sign in
  • Create Account
  • Home
  • Php
  • Worker Gearman from Cli Console to Php

Worker Gearman from Cli Console to Php

In order not to describe again, I give a link to the details . Based on this topic, we will try to start the worker through the console and give it some work through the client.

Let's make some changes to the code. Instead of saving data to a file, we will use console output.

file_put_contents("php://stdin", 'output string');

I will demonstrate the server.php file with the new changes.

<?php


$gmw = new GearmanWorker();

/**
 * For now, consider the default initialization of addServer()
 * This method is needed to declare which machine this worker is running on
 */
$gmw->addServer();

/**
 * log_client - from the client side use this alice
 * work_log - the function that the worker will throw on if
  * something will come to alice log_client.
 */
$gmw->addFunction('log_client', 'work_log');

/**
 * Specially done
 * If you just declare $gmw->work(), then the task will end immediately
 * after execution. That is, it will only work once.
 */
while($gmw->work());

/**
 * Write logs to a file
 * @param JSON $param - Accepts only a string, so pass it to json if needed
&nbsp ;*/
function work_log($param) {
    /*Retrieves data sent by the client*/
    $data = $param->workload();
    
    /**
     * We artificially create a load to simulate a long wait.
     * Here we will see that the client script will not wait for the end of 100 seconds,
     * and hang up the task and forget about it.
     */
    for ($i = 0; $i < 100; $i++) {
        sleep(1);
        file_put_contents("php://stdin", $data); // Changed for console output
    }
    
}

Launching from the console is done like this (our project is in the /var/www/test1.loc directory):

php /var/www/test1.loc/server.php

This line in the console will hang the worker on hold. It will wait until the console closes or the max_input_time in php.ini times out.

Ожидание воркера

It can be seen that the console is waiting (Warning indicates a possible problem in the Gearman library itself). After running client.php , you can clearly see that everything is completed in the browser, and the console works by itself. If you close the console and then start the worker again, it will continue to work from the moment it left off.

Работа воркера

19 May 18
813
0

Comments

Name
E-mail
Rating
Review

Other articles from the category

25 April 2022

Create and download CSV in PHP

Consider the possibility of quickly creating a CSV file with automatic file download. Consider the formation, separators and header for the ability to download the file.

19 June 2019

ImageCMS Templates 4.10-4.12.1

Latest templates from ImageCMS 4.12, authorization is required to download.

26 January 2019

Long-term storage of the basket in the online store

Consider options for popular options for storing goods in a shopping cart in an online store. Let's outline the pros and cons of such storage. Consider options for long-term storage of the basket.

17 January 2019

License key for ImageCMS 4.9-4.12.1 Pro and Pre

Creating a key for imageCMS 4.9-4.12.1 Pro and Pre. You must be logged in to receive it.

07 December 2018

$_SERVER[DOCUMENT_ROOT] in CLI or Cron

When running the script from the console, there is no DOCUMENT_ROOT in $_SERVER. Let's try to get around this in our own ways, catch the file directory.

31 October 2018

Analysis of loaded parts of Php code with xhprof

After developing any tool in PHP, the question becomes how resourceful the created code is and what elements it still affects. Let's take a look at xhprof installation, configuration, and how to work with xhprof.

18 July 2018

Grouping conditions in an ORM Propel query (condition, combine)

Let's analyze the possibility of combining conditions in a query by groups in Propel. Consider an example of filtering by fields using ->condition() and ->combine().

14 June 2018

Authorization 1C on the site PHP_AUTH_USER on CentOS apache

Faced the problem of authorization 1s on the site. For some reason, the server did not accept the PHP_AUTH_USER and PHP_AUTH_PW parameters from it. Let's take a closer look at the solution and bypassing these parameters in $_SERVER .

Categories

  • Unix OS
  • Php
  • MySQL
  • JavaScript
  • Package Managers
  • Docker
  • Seo

Latest comments

Добрый день, Сергей. Я на более новых версиях блют...
root-i
23.02.23
Пробовал на transmart колонке. Ничего из перечисле...
Сергей
20.02.23
HenryMit, может быть
root-i
07.02.23
Неофрейдизм — это… Определение, принципы, представ...
HenryMit
07.02.23

I share information in which I needed help and spent a lot of time figuring it out. If the information helped at least one person, then this site was not created in vain.

Thank you for the continuation of the site:
Contacts

Telegram Viber Mail

Search for articles

  • Sign in
  • Create Account

Powered by chmod -R