Skip to content

Commit 3951b48

Browse files
author
Skamander
committed
Initial commit
1 parent 06c7dc2 commit 3951b48

10 files changed

Lines changed: 284 additions & 0 deletions

File tree

php-silex/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/app/cache
2+
/app/logs
3+
/bin
4+
/vendors
5+
/build
6+
/dist
7+
.DS_Store
8+
/tags
9+
.idea

php-silex/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Cake PHP Benchmarking Test
2+
3+
This is the Silex PHP portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
4+
5+
### JSON Encoding Test
6+
Uses the PHP standard [JSON encoder](http://www.php.net/manual/en/function.json-encode.php).
7+
8+
* [JSON test controller](web/index.php)
9+
10+
11+
### Data-Store/Database Mapping Test
12+
Uses the Doctrine DBAL functionality.
13+
14+
* [DB test controller](web/index.php)
15+
16+
17+
## Infrastructure Software Versions
18+
The tests were run with:
19+
20+
* [Symfony Version 2.2.1](http://silex.sensiolabs.org/)
21+
* [PHP Version 5.4.13](http://www.php.net/) with FPM and APC
22+
* [nginx 1.2.7](http://nginx.org/)
23+
* [MySQL 5.5.29](https://dev.mysql.com/)
24+
25+
## Test URLs
26+
### JSON Encoding Test
27+
28+
http://localhost/json
29+
30+
### Data-Store/Database Mapping Test
31+
32+
http://localhost/db
33+
34+
### Variable Query Test
35+
36+
http://localhost/db?queries=2

php-silex/__init__.py

Whitespace-only changes.

php-silex/benchmark_config

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"framework": "php-silex",
3+
"tests": [{
4+
"default": {
5+
"setup_file": "setup",
6+
"json_url": "/json",
7+
"db_url": "/db",
8+
"query_url": "/db?queries=",
9+
"port": 8080,
10+
"sort": 14
11+
}
12+
}]
13+
}

php-silex/composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"require": {
3+
"silex/silex": "1.0.*@dev",
4+
"doctrine/dbal": ">=2.2.0,<2.4.0-dev"
5+
}
6+
}

php-silex/deploy/nginx.conf

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#user nobody;
2+
worker_processes 8;
3+
4+
#error_log logs/error.log;
5+
#error_log logs/error.log notice;
6+
#error_log logs/error.log info;
7+
8+
#pid logs/nginx.pid;
9+
10+
11+
events {
12+
worker_connections 1024;
13+
}
14+
15+
16+
http {
17+
include /usr/local/nginx/conf/mime.types;
18+
default_type application/octet-stream;
19+
20+
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
21+
# '$status $body_bytes_sent "$http_referer" '
22+
# '"$http_user_agent" "$http_x_forwarded_for"';
23+
24+
#access_log logs/access.log main;
25+
26+
sendfile on;
27+
#tcp_nopush on;
28+
29+
#keepalive_timeout 0;
30+
keepalive_timeout 65;
31+
32+
#gzip on;
33+
34+
server {
35+
listen 8080;
36+
server_name localhost;
37+
38+
#charset koi8-r;
39+
40+
#access_log logs/host.access.log main;
41+
42+
#location / {
43+
# root html;
44+
# index index.html index.htm;
45+
#}
46+
47+
#error_page 404 /404.html;
48+
49+
# redirect server error pages to the static page /50x.html
50+
#
51+
#error_page 500 502 503 504 /50x.html;
52+
#location = /50x.html {
53+
# root html;
54+
#}
55+
56+
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
57+
#
58+
#location ~ \.php$ {
59+
# proxy_pass http://127.0.0.1;
60+
#}
61+
62+
root /home/ubuntu/FrameworkBenchmarks/php-silex/web/;
63+
index index.php;
64+
65+
location / {
66+
try_files $uri $uri/ /index.php?$uri&$args;
67+
}
68+
69+
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
70+
#
71+
location ~ \.php$ {
72+
try_files $uri =404;
73+
fastcgi_pass 127.0.0.1:9001;
74+
fastcgi_index index.php;
75+
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
76+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
77+
include /usr/local/nginx/conf/fastcgi_params;
78+
}
79+
80+
# deny access to .htaccess files, if Apache's document root
81+
# concurs with nginx's one
82+
#
83+
#location ~ /\.ht {
84+
# deny all;
85+
#}
86+
}
87+
88+
89+
# another virtual host using mix of IP-, name-, and port-based configuration
90+
#
91+
#server {
92+
# listen 8000;
93+
# listen somename:8080;
94+
# server_name somename alias another.alias;
95+
96+
# location / {
97+
# root html;
98+
# index index.html index.htm;
99+
# }
100+
#}
101+
102+
103+
# HTTPS server
104+
#
105+
#server {
106+
# listen 443;
107+
# server_name localhost;
108+
109+
# ssl on;
110+
# ssl_certificate cert.pem;
111+
# ssl_certificate_key cert.key;
112+
113+
# ssl_session_timeout 5m;
114+
115+
# ssl_protocols SSLv2 SSLv3 TLSv1;
116+
# ssl_ciphers HIGH:!aNULL:!MD5;
117+
# ssl_prefer_server_ciphers on;
118+
119+
# location / {
120+
# root html;
121+
# index index.html index.htm;
122+
# }
123+
#}
124+
125+
}

php-silex/deploy/php-silex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<VirtualHost *:8080>
2+
Alias /php-silex/ "/home/ubuntu/FrameworkBenchmarks/php-silex/web/"
3+
<Directory /home/ubuntu/FrameworkBenchmarks/php-silex/web/>
4+
Options Indexes FollowSymLinks MultiViews
5+
#AllowOverride None
6+
Order allow,deny
7+
allow from all
8+
</Directory>
9+
</VirtualHost>

php-silex/setup.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
import subprocess
3+
import sys
4+
import setup_util
5+
from os.path import expanduser
6+
7+
home = expanduser("~")
8+
9+
def start(args):
10+
setup_util.replace_text("php-silex/web/index.php", "192.168.100.102", "" + args.database_host + "")
11+
setup_util.replace_text("php-silex/deploy/php-silex", "\".*\/FrameworkBenchmarks", "\"" + home + "/FrameworkBenchmarks")
12+
setup_util.replace_text("php-silex/deploy/php-silex", "Directory .*\/FrameworkBenchmarks", "Directory " + home + "/FrameworkBenchmarks")
13+
setup_util.replace_text("php-silex/deploy/nginx.conf", "root .*\/FrameworkBenchmarks", "root " + home + "/FrameworkBenchmarks")
14+
15+
try:
16+
#subprocess.check_call("sudo cp cake/deploy/cake /etc/apache2/sites-available/", shell=True)
17+
#subprocess.check_call("sudo a2ensite cake", shell=True)
18+
#subprocess.check_call("sudo chown -R www-data:www-data cake", shell=True)
19+
#subprocess.check_call("sudo /etc/init.d/apache2 start", shell=True)
20+
subprocess.check_call("composer install", shell=True)
21+
subprocess.check_call("sudo php-fpm --fpm-config config/php-fpm.conf -g " + home + "/FrameworkBenchmarks/php-silex/deploy/php-fpm.pid", shell=True)
22+
subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/php-silex/deploy/nginx.conf", shell=True)
23+
return 0
24+
except subprocess.CalledProcessError:
25+
return 1
26+
def stop():
27+
try:
28+
subprocess.call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True)
29+
subprocess.call("sudo kill -QUIT $( cat php-silex/deploy/php-fpm.pid )", shell=True)
30+
#subprocess.check_call("sudo a2dissite cake", shell=True)
31+
#subprocess.check_call("sudo /etc/init.d/apache2 stop", shell=True)
32+
#subprocess.check_call("sudo chown -R $USER:$USER cake", shell=True)
33+
return 0
34+
except subprocess.CalledProcessError:
35+
return 1

php-silex/web/.htaccess

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# /web/.htaccess
2+
<IfModule mod_rewrite.c>
3+
Options -MultiViews
4+
5+
RewriteEngine On
6+
RewriteCond %{REQUEST_FILENAME} !-f
7+
RewriteRule ^ index.php [L]
8+
</IfModule>

php-silex/web/index.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
use Symfony\Component\HttpFoundation\JsonResponse;
4+
use Symfony\Component\HttpFoundation\Request;
5+
6+
error_reporting(-1);
7+
8+
require_once __DIR__.'/../vendor/autoload.php';
9+
10+
$app = new Silex\Application();
11+
12+
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
13+
'db.options' => array(
14+
'driver' => 'pdo_mysql',
15+
'host' => '192.168.100.102',
16+
'dbname' => 'hello_world',
17+
'user' => 'benchmarkdbuser',
18+
'password' => 'benchmarkdbpass',
19+
),
20+
));
21+
22+
$app->get('/json', function() {
23+
return new JsonResponse(array("message" => "Hello World!"));
24+
});
25+
26+
$app->get('/db', function(Request $request) use ($app) {
27+
$queries = $request->query->getInt('queries', 1);
28+
// possibility for micro enhancement could be the use of SplFixedArray -> http://php.net/manual/de/class.splfixedarray.php
29+
$worlds = array();
30+
31+
for($i = 0; $i < $queries; ++$i) {
32+
$worlds[] = $app['db']->fetchAssoc('SELECT * FROM World WHERE id = ?', array(mt_rand(1, 10000)));
33+
}
34+
35+
return new JsonResponse($worlds);
36+
});
37+
38+
39+
$app->run();
40+
41+
42+
43+

0 commit comments

Comments
 (0)