1. Go to this page and download the library: Download depaco/codeigniter-swoole library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
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());
}
}
// ------------------------------------------------------------------------------
}
shell
// 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
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.