2017 © Pedro Peláez
 

library codeigniter-swoole

A swoole adapter for Codeigniter 3.0+

image

lanlin/codeigniter-swoole

A swoole adapter for Codeigniter 3.0+

  • Sunday, July 1, 2018
  • by lanlin
  • Repository
  • 1 Watchers
  • 11 Stars
  • 28 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 14 Versions
  • 4 % Grown

The README.md

Codeigniter Swoole Adapter

You want long-run task? timers? FPM to CLI? Code reusing in both FPM & CLI mode?, (*1)

"It's so easy!", (*2)

This adapter would make it so easy to using swoole within Codeigniter framework., (*3)

With this adapter, you can start a task(CLI) any where(FPM) you want from your code., (*4)

That's means you can start a CLI task from a FPM process., (*5)

Install

composer require lanlin/codeigniter-swoole

How to

  1. first, of course you must install codeigniter-swoole to your codeigniter project.
  2. (this step is option) copy these two config files swoole.php and timers.php from src/Helper to your application/config folder.
  3. start swoole server php index.php swoole/server/start
  4. you can use \CiSwoole\Core\Client::send($data) to start a task now!
  5. there's no step 5.

What is a task?

A task is just a method of your codeigniter controlloer, so almost any controller method can be used as a task., (*6)

Let's see the code, (*7)

\CiSwoole\Core\Client::send(
[
    'route'  => 'your/route/uri/to/a/method'
    'params' => ['test' => 666]
]);

The route is used for find which method to be call as a task, and params is the parameters array that you may want to pass to the task., (*8)

So, that's all of it!, (*9)

Server CLI Commands


// start the swoole server php index.php swoole/server/start // stop the swoole server php index.php swoole/server/stop // reload all wokers of swoole server php index.php swoole/server/reload

A little more

The step 2 copied files were config files for this adapter., (*10)

swoole.php file can set host, port, log file and so on., (*11)

timers.php file can set some timer methods for swoole server, these timers will be started once the server inited., (*12)

You can copy tests/application to your application for testing. The demos are same as below shows., (*13)

class Test extends CI_Controller
{

    // ------------------------------------------------------------------------------

    /**
     * here's the task 'tests/test/task'
     */
    public function task()
    {
        $data = $this->input->post();     // as you see, params worked like normally post data

        log_message('info', var_export($data, true));
    }

    // ------------------------------------------------------------------------------

    /**
     * here's the timer method
     *
     * you should copay timers.php to your config folder,
     * then add $timers['tests/test/task_timer'] = 10000; and start the swoole server.
     *
     * this method would be called every 10 seconds per time.
     */
    public function task_timer()
    {
        log_message('info', 'timer works!');
    }

    // ------------------------------------------------------------------------------

    /**
     * send data to task
     */
    public function send()
    {
        try
        {
            \CiSwoole\Core\Client::send(
            [
                'route'  => 'tests/test/task',
                'params' => ['hope' => 'it works!'],
            ]);
        }
        catch (\Exception $e)
        {
            log_message('error', $e->getMessage());
            log_message('error', $e->getTraceAsString());
        }
    }

    // ------------------------------------------------------------------------------

}

License

This project is licensed under the MIT license., (*14)

补充说明

codeigniter-swoole 的主要应用场景, (*15)

The Versions

01/07 2018

dev-master

9999999-dev https://github.com/lanlin/codeigniter-swoole

A swoole adapter for Codeigniter 3.0+

  Sources   Download

MIT

The Requires

  • php >=5.6
  • ext-swoole ^2.0.0

 

The Development Requires

by Avatar lanlin

php task codeigniter swoole adapter timers swoole codeigniter combind long run

01/07 2018

2.0.0

2.0.0.0 https://github.com/lanlin/codeigniter-swoole

A swoole adapter for Codeigniter 3.0+

  Sources   Download

MIT

The Requires

  • php >=5.6
  • ext-swoole ^2.0.0

 

The Development Requires

by Avatar lanlin

php task codeigniter swoole adapter timers long run

15/01 2016

1.2.0

1.2.0.0

Simple package for use swoole under codeigniter.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar lanlin

swoole codeigniter combind

29/10 2015

1.1.1

1.1.1.0

Simple package for use swoole under codeigniter.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar lanlin

swoole codeigniter combind

16/10 2015

1.0.9

1.0.9.0

Simple package for use swoole under codeigniter.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar lanlin

swoole codeigniter combind

16/10 2015

1.1.0

1.1.0.0

Simple package for use swoole under codeigniter.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar lanlin

swoole codeigniter combind

15/10 2015

1.0.7

1.0.7.0

Simple package for use swoole under codeigniter.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar lanlin

swoole codeigniter combind

14/10 2015

1.0.6

1.0.6.0

Simple package for use swoole under codeigniter.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar lanlin

swoole codeigniter combind

14/10 2015

1.0.5

1.0.5.0

Simple package for use swoole under codeigniter.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar lanlin

swoole codeigniter combind

13/10 2015

1.0.4

1.0.4.0

Simple package for use swoole under codeigniter.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar lanlin

swoole codeigniter combind

13/10 2015

1.0.3

1.0.3.0

Simple package for use swoole under codeigniter.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar lanlin

swoole codeigniter combind

13/10 2015

1.0.2

1.0.2.0

Simple package for use swoole under codeigniter.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar lanlin

swoole codeigniter combind

13/10 2015

1.0.1

1.0.1.0

Simple package for use swoole under codeigniter.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar lanlin

swoole codeigniter combind

13/10 2015

1.0.0

1.0.0.0

Simple package for use swoole under codeigniter.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar lanlin

swoole codeigniter combind