Git Product home page Git Product logo

Comments (15)

walkor avatar walkor commented on May 18, 2024

https://github.com/walkor/workerman.net/blob/master/applications/Doc3.workerman.net/src/SUMMARY.md
Here is the docs,but only chinese.
Yes, you can get the arguments for your script.

from workerman.

IngwiePhoenix avatar IngwiePhoenix commented on May 18, 2024

When will english docs be available?

I worked out the API, sort of, with a lot of print_r()'s... but having the actual docs would be helpful.

from workerman.

walkor avatar walkor commented on May 18, 2024

English document may be available after 2 months.

from workerman.

IngwiePhoenix avatar IngwiePhoenix commented on May 18, 2024

Okay, sounds good! But maybe you can answer me a little question.

Which callback is used upon client initialization? Like, there is onConnect and such. But is there a function that is called each time the worker is made, on the worker's end? I saw onWorkerCreate...but I am not sure if this is called from the main process or the worker process.

from workerman.

walkor avatar walkor commented on May 18, 2024

Yes, onConnect will be triggered when new client come.
onWorkerStart will be triggered when worker is made.
onWorkerStop will be triggered when worker is down.
And on{...} is allways called from worker process.

from workerman.

IngwiePhoenix avatar IngwiePhoenix commented on May 18, 2024

Awesome. What are the arguments given to the various callbacks? Only the worker object or more?

from workerman.

walkor avatar walkor commented on May 18, 2024

$connection is the instance of TcpConnection and $worker is the instance of Worker.

Worker's callback and arguments

onWorkerStart($worker)    
onWorkerStop($worker)
onConnect($connection) 
onMessage($connection, $data)  
onClose($connection)   
onBufferFull($connection)  //Emitted when $connection‘s write buffer becomes full.  
onBufferDrain($connection)  //Emitted when $connection‘s write buffer becomes empty.  
onError($connection, $error_code, $error_msg)  

TcpConnection's Api and arguments

send($data)  // Send data.
getRemoteIp()
getRemotePort()
close()  //Close connection.
pauseRecv()  //Pauses the reading of data.   
resumeRecv()   //Resumes reading.  

from workerman.

IngwiePhoenix avatar IngwiePhoenix commented on May 18, 2024

Very nice! This helps me a lot!

One last thing though. I want to intentionally restart a worker. Currently, I am doing this by sending SIGUSR1 to the process itself: http://git.ingwie.me/ingwie/bird3/blob/master/php-lib/YiiApp.php (See YiiApp::stop())

Is there an actual "right" way to relaunch a worker?

Does onClose() reffer to when the client closes the connection to the worker?

from workerman.

walkor avatar walkor commented on May 18, 2024

If you start workerman by command php start.php start, you can restart all workers by command php start.php restart or php start.php reload for gracefull restart.

You can also send SIGINT or SIGUSR1 signal to the main process, then all worker processes will be restart or reload. If you send SIGINT or SIGUSR1 signal to one worker process, then the worker process will be restart or reload.

Any end closed connection will emitted onClose.

from workerman.

IngwiePhoenix avatar IngwiePhoenix commented on May 18, 2024

Is there a way to reload a worker, but keeping its statistics? Reloading a worker also means that the stats for connections and such are reset to 0.

from workerman.

walkor avatar walkor commented on May 18, 2024

It difficult to do that.
Workerman's reload is restart worker processe(s).When a process exit everything will be destroyed.
Maybe Classkit is useful for what you want, but need a lot of codes to achieve it.

from workerman.

IngwiePhoenix avatar IngwiePhoenix commented on May 18, 2024

Actually it is not that hard.

Each time a worker is created, use the uniqid() function and save that as a variable. Then offer this very worker a restart function. This restart function should mention to the parent process that it wants to restart and give it it’s unique ID. The master sends a signal to finally stop the worker. Then, the process re-fork()s itself and assigns the previous ID again.

You then can assign this very ID to the entries in the worker table - that way the workers can keep their state.

This is just an diea of mine though!

Kind regards, Ingwie.

from workerman.

walkor avatar walkor commented on May 18, 2024

For example.
You can't reassign the original connnections to the new worker process, because the connections are closed when original worker process stoped.
Main process dose not hold connnections. Every worker processes hold connections for themselves.

from workerman.

walkor avatar walkor commented on May 18, 2024

English docs are available. English docs

from workerman.

IngwiePhoenix avatar IngwiePhoenix commented on May 18, 2024

Awesome work! I just looked through them, they are very nice. :)

from workerman.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.