PHP code example of flyokai / misc

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

    

flyokai / misc example snippets


use Flyokai\Misc\CryptKey;

$key = new CryptKey('/path/to/private.pem', passPhrase: null, keyPermissionsCheck: true);

$key->getKeyContents();   // PEM contents (string)
$key->getKeyPath();
$key->getPassPhrase();

use Flyokai\Misc\ProfilerFacade;

ProfilerFacade::setEnabled(true);
ProfilerFacade::start('request');
ProfilerFacade::start('request->db->query');
// … work …
ProfilerFacade::stop('request->db->query');
ProfilerFacade::stop('request');

foreach (ProfilerFacade::getAllStat() as $line) {
    echo $line, "\n";
    // request: 12.34 ms, count=1, avg=12.34 ms, real=512 KB, emalloc=200 KB
}

use Flyokai\Misc\PsrServerAdapter;

$adapter = new PsrServerAdapter();

$psrRequest  = $adapter->toPsrServerRequest($ampRequest);
$ampResponse = $adapter->fromPsrServerResponse($psrResponse, $ampRequest);

use Flyokai\Misc\SharedSequence;

$seq = new SharedSequence();

// Fiber A
$seq->await(5);   // suspends until position >= 5

// Fiber B
$seq->resume(5);  // advances to position 6, resumes any waiters whose target is <= 5