PHP code example of dongqibin / context

1. Go to this page and download the library: Download dongqibin/context 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/ */

    

dongqibin / context example snippets




use Dongqibin\Context\Client;

//获取当前协程上下文key的值
Client::get('key', Co::getCid());

//如果获取当前协程上下文的数据,可以忽略get方法第二个参数 . 简化为如下代码
Client::get('key');

//设置协程上下文key的值
$cid = 1; //获取其他协程ID
Client::set('key', 'val', $cid);

//如果设置当前协程上下文key的值,可省略第三个参数$cid
Client::set('key', 'val');