Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update PHP Fat-Free Framework #1734

Merged
merged 13 commits into from
Mar 16, 2016
9 changes: 3 additions & 6 deletions frameworks/PHP/fat-free/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ RewriteEngine On
#
RewriteBase /

RewriteCond %{REQUEST_URI} \.ini$
RewriteRule \.ini$ - [R=404]

RewriteCond %{REQUEST_URI} \.html?$
RewriteRule \.html?$ - [R=404]
RewriteRule ^(tmp)\/|\.ini$ - [R=404]

RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule .* index.php [L,QSA]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
6 changes: 3 additions & 3 deletions frameworks/PHP/fat-free/benchmark_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"json_url": "/json",
"plaintext_url": "/plaintext",
"db_url": "/db-orm",
"query_url": "/db-orm/",
"query_url": "/db-orm-multiple/",
"update_url": "/update-orm/",
"port": 8080,
"approach": "Realistic",
Expand All @@ -26,7 +26,7 @@
"raw": {
"setup_file": "setup",
"db_url": "/db",
"query_url": "/db/",
"query_url": "/db-multiple/",
"fortune_url": "/fortune",
"update_url": "/update-raw/",
"port": 8080,
Expand All @@ -43,6 +43,6 @@
"display_name": "fat-free",
"notes": "",
"versus": "php"
}
}
}]
}
91 changes: 91 additions & 0 deletions frameworks/PHP/fat-free/benchmark_config_bak.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"framework": "fat-free",
"tests": [{
"default": {
"setup_file": "setup",
"json_url": "/json",
"plaintext_url": "/plaintext",
"db_url": "/db-orm",
"query_url": "/db-orm-multiple/",
"update_url": "/update-orm/",
"port": 8080,
"approach": "Realistic",
"classification": "Fullstack",
"database": "MySQL",
"framework": "Fat Free Framework",
"language": "PHP",
"orm": "Full",
"platform": "PHP-FPM",
"webserver": "nginx",
"os": "Linux",
"database_os": "Linux",
"display_name": "fat-free",
"notes": "",
"versus": "php"
},
"raw": {
"setup_file": "setup",
"db_url": "/db",
"query_url": "/db-multiple/",
"fortune_url": "/fortune",
"update_url": "/update-raw/",
"port": 8080,
"approach": "Realistic",
"classification": "Fullstack",
"database": "MySQL",
"framework": "Fat Free Framework",
"language": "PHP",
"orm": "Raw",
"platform": "PHP-FPM",
"webserver": "nginx",
"os": "Linux",
"database_os": "Linux",
"display_name": "fat-free",
"notes": "",
"versus": "php"
},
"php5": {
"setup_file": "setup_php5",
"json_url": "/json",
"plaintext_url": "/plaintext",
"db_url": "/db-orm",
"query_url": "/db-orm-multiple/",
"update_url": "/update-orm/",
"port": 8080,
"approach": "Realistic",
"classification": "Fullstack",
"database": "MySQL",
"framework": "Fat Free Framework",
"language": "PHP5",
"orm": "Full",
"platform": "PHP-FPM",
"webserver": "nginx",
"os": "Linux",
"database_os": "Linux",
"display_name": "fat-free",
"notes": "",
"versus": "php"
},
"php5-raw": {
"setup_file": "setup_php5",
"db_url": "/db",
"query_url": "/db-multiple/",
"fortune_url": "/fortune",
"update_url": "/update-raw/",
"port": 8080,
"approach": "Realistic",
"classification": "Fullstack",
"database": "MySQL",
"framework": "Fat Free Framework",
"language": "PHP5",
"orm": "Raw",
"platform": "PHP-FPM",
"webserver": "nginx",
"os": "Linux",
"database_os": "Linux",
"display_name": "fat-free",
"notes": "",
"versus": "php"
}
}]
}
7 changes: 5 additions & 2 deletions frameworks/PHP/fat-free/deploy/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ worker_processes 8;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
error_log stderr error;

#pid logs/nginx.pid;

Expand All @@ -12,6 +13,7 @@ events {
worker_connections 1024;
}


http {
include /usr/local/nginx/conf/mime.types;
default_type application/octet-stream;
Expand All @@ -21,6 +23,7 @@ http {
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;
access_log off;

sendfile on;
#tcp_nopush on;
Expand Down Expand Up @@ -62,7 +65,7 @@ http {
# proxy_pass http://127.0.0.1;
#}

root /home/tfb/FrameworkBenchmarks/php-fatfree/;
root /home/ubuntu/FrameworkBenchmarks/fat-free/;
index index.php;

location / {
Expand Down Expand Up @@ -125,4 +128,4 @@ http {
# }
#}

}
}
9 changes: 0 additions & 9 deletions frameworks/PHP/fat-free/deploy/php

This file was deleted.

110 changes: 78 additions & 32 deletions frameworks/PHP/fat-free/index.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
<?php
// drop startup errors
if (function_exists('error_clear_last'))
error_clear_last();

error_reporting(0);

/** @var Base $f3 */
$f3=require('lib/base.php');
$f3=require('src/base.php');

error_reporting(-1);

$f3->set('DEBUG',2);
$f3->set('HIGHLIGHT',false);
$f3->set('CACHE','folder=tmp/cache/');
$f3->set('UI','ui/');
$f3->set('ONERROR',function($f3){
echo $f3->get('ERROR.code').': '.$f3->get('ERROR.text')."\n".$f3->get('ERROR.trace');
});

$f3->set('DBS',array('mysql:host=localhost;port=3306;dbname=hello_world','benchmarkdbuser','benchmarkdbpass'));

// http: //www.techempower.com/benchmarks/#section=code

// JSON test
Expand All @@ -18,18 +29,31 @@
});


// DB RAW test
$f3->route(
array(
'GET /db', // database-single-query
'GET /db/@queries', // database-multiple-queries
// DB RAW test database-single-query
$f3->route('GET /db', function ($f3,$params) {
/** @var Base $f3 */
$dbc = $f3->get('DBS');
$db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
$id = mt_rand(1, 10000);
$res = $db->exec('SELECT id, randomNumber FROM World WHERE id = ?',$id,0,false);
$result = array(
'id' => (int) $res[0]['id'],
'randomNumber' => (int) $res[0]['randomNumber'],
);
header("Content-type: application/json");
echo json_encode($result);
}
);

// DB RAW test database-multiple-query
$f3->route(array(
'GET /db-multiple',
'GET /db-multiple/@queries',
),
function ($f3,$params) {
/** @var Base $f3 */
$single = !isset($params['queries']);
if ($single)
$queries = 1;
else {
$queries = 1;
if (isset($params['queries'])) {
$queries = (int) $params['queries'];
$queries = ($queries < 1) ? 1 : (($queries > 500) ? 500 : $queries);
}
Expand All @@ -39,25 +63,39 @@ function ($f3,$params) {
for ($i = 0; $i < $queries; $i++) {
$id = mt_rand(1, 10000);
$res = $db->exec('SELECT id, randomNumber FROM World WHERE id = ?',$id,0,false);
$result[] = $res[0];
$result[] = array(
'id' => (int) $res[0]['id'],
'randomNumber' => (int) $res[0]['randomNumber'],
);
}
header("Content-type: application/json");
echo json_encode($single ? $result[0] : $result);
echo json_encode($result);
}
);

// DB ORM test
// DB ORM test database-single-query
$f3->route('GET /db-orm', function ($f3, $params) {
/** @var Base $f3 */
$dbc = $f3->get('DBS');
$db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
$mapper = new \DB\SQL\Mapper($db,'World');
$id = mt_rand(1, 10000);
$mapper->load(array('id = ?',$id));
header("Content-type: application/json");
echo json_encode($mapper->cast());
}
);

// DB ORM test database-multiple-queries
$f3->route(
array(
'GET /db-orm', // database-single-query
'GET /db-orm/@queries', // database-multiple-queries
'GET /db-orm-multiple',
'GET /db-orm-multiple/@queries', // database-multiple-queries
),
function ($f3, $params) {
/** @var Base $f3 */
$single = !isset($params['queries']);
if ($single)
$queries = 1;
else {
$queries = 1;
if(isset($params['queries'])) {
$queries = (int) $params['queries'];
$queries = ($queries < 1) ? 1 : (($queries > 500) ? 500 : $queries);
}
Expand All @@ -71,12 +109,13 @@ function ($f3, $params) {
$result[] = $mapper->cast();
}
header("Content-type: application/json");
echo json_encode($single ? $result[0] : $result);
echo json_encode($result);
}
);


$f3->route('GET /plaintext', function ($f3) {
header("Content-type: text/plain");
echo "Hello, World!";
});

Expand All @@ -97,11 +136,16 @@ function ($f3, $params) {
});


$f3->route('GET /update-raw/@queries', function($f3,$params) {
$f3->route(array(
'GET /update-raw',
'GET /update-raw/@queries'
), function($f3,$params) {
/** @var Base $f3 */
$queries = (int) $params['queries'];
$queries = ($queries < 1) ? 1 : (($queries > 500) ? 500 : $queries);

$queries = 1;
if (isset($params['queries'])) {
$queries = (int) $params['queries'];
$queries = ( $queries < 1 ) ? 1 : ( ( $queries > 500 ) ? 500 : $queries );
}
$dbc = $f3->get('DBS');
$db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));

Expand All @@ -117,18 +161,21 @@ function ($f3, $params) {
$db->exec('UPDATE World SET randomNumber = :ranNum WHERE id = :id', array(':ranNum'=>$rnu,':id'=>$id),0,false);
$result[] = $row;
}

header("Content-type: application/json");
echo json_encode($result);

});


$f3->route('GET /update-orm/@queries', function($f3,$params) {
$f3->route(array(
'GET /update-orm',
'GET /update-orm/@queries'
), function($f3,$params) {
/** @var Base $f3 */
$queries = (int) $params['queries'];
$queries = ($queries < 1) ? 1 : (($queries > 500) ? 500 : $queries);

$queries = 1;
if (isset($params['queries'])) {
$queries = (int) $params['queries'];
$queries = ($queries < 1) ? 1 : (($queries > 500) ? 500 : $queries);
}
$dbc = $f3->get('DBS');
$db = new \DB\SQL($dbc[0],$dbc[1],$dbc[2],array( \PDO::ATTR_PERSISTENT => TRUE ));
$world = new \DB\SQL\Mapper($db,'World');
Expand All @@ -143,7 +190,6 @@ function ($f3, $params) {
}
header("Content-type: application/json");
echo json_encode($result);

});

$f3->run();
Loading