Home>Article>PHP Framework> About the registration tree mode in Workerman

About the registration tree mode in Workerman

藏色散人
藏色散人 forward
2020-01-29 14:14:15 1791browse

The following columnWorkerman Tutorialwill introduce you to the registration tree mode in Workerman. I hope it will be helpful to friends in need!

About the registration tree mode in Workerman

Registration tree mode is to hang the object into the attribute array of a class. Next time, it will be fetched directly from this array to keep it globally unique, usually at the project entrance. Useful during initialization.

Inworkerman, the very beginning is the application of registration tree mode. The following is its simulation

workerId=spl_object_hash($this); static::$_workers[$this->workerId]=$this; } public static function runAll(){ foreach (static::$_workers as $worker) { var_dump($worker); } } } new Worker(); new Worker(); Worker::runAll();

In the constructor of Worker, hang the current new object into the static variable attribute array of the Worker class, and fetch it directly from that array the next time it is used

About the registration tree mode in Workerman

The above is the detailed content of About the registration tree mode in Workerman. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete