Giter Club home page Giter Club logo

process's Introduction

What's This?

这是一个为方便初级 phper 使用 php 进行多进程开发的库。
用不到十行的代码,实现一个以守护进程方式启动的多进程程序。

一般用于消息队列的消费者端、多进程爬虫等场景

初始化运行库

require './vendor/autoload.php';

$app = new \Lisao\Process\Process([
    'process_count' => 4 , //运行的线程数
    'process_save' => './process.pid' //线程 id 保存路径,用于停止进程时使用
]);

闭包运行

/*
 * $work_id 为工作id,从0开始,根据线程数顺序递增。
 * 用于区分进程,指派任务
 */
$app->start(function($work_id){
    echo "我启动了,工作ID:{$work_id} \n";
});

类方法运行

class obj {
    public function test($work_id) {
        echo "我启动了,工作ID:{$work_id} \n";
    }
}

$obj = new obj();
$app->start($obj, 'test');

停止运行

$app->stop();

process's People

Contributors

yuanxin32323 avatar

Watchers

 avatar

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.