PHP code example of kislayphp / core
1. Go to this page and download the library: Download kislayphp/core 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/ */
kislayphp / core example snippets
$app = new Kislay\Core\App();
$app->setOption('log', false);
$app->setOption('request_id', false);
$app->setOption('trace', false);
$app->use('/api', function ($req, $res) {
$res->set('X-Powered-By', 'Kislay');
return true;
});
$app->get('/api/users/:id', function ($req, $res) {
$res->json([
'id' => $req->param('id'),
'search' => $req->query('q', ''),
], 200);
});
$app->post('/api/users/:id', function ($req, $res) {
$res->json([
'id' => $req->param('id'),
'email' => $req->input('email'),
], 200);
});
$app->listen('0.0.0.0', 8080);
$req->param('id');
$req->query('name');
$req->input('email');
$req->getJson();
$req->header('authorization');
$app->setOption('async', true);
$app->setOption('async_threads', 4);
async(function () {
return heavy_computation();
})->then(function ($result) {
echo $result;
});
$http = new Kislay\Core\AsyncHttp();
$http->get('https://api.example.com/data');
$http->retry(2, 200);
$http->executeAsync()->then(function () use ($http) {
echo $http->getResponseCode();
});
bash
php run-tests.php