Browse Source

Merge branch 'master' of https://github.com/changloong/FrameworkBenchmarks

Patrick Falls 12 years ago
parent
commit
e925441949

+ 9 - 0
php-silica/.gitignore

@@ -0,0 +1,9 @@
+/app/cache
+/app/logs
+/bin
+/vendors
+/build
+/dist
+.DS_Store
+/tags
+.idea

+ 36 - 0
php-silica/README.md

@@ -0,0 +1,36 @@
+# Silica Benchmarking Test
+
+This is the Silica PHP portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
+
+### JSON Encoding Test
+Uses the PHP standard [JSON encoder](http://www.php.net/manual/en/function.json-encode.php).
+
+* [JSON test controller](web/index.php)
+
+
+### Data-Store/Database Mapping Test
+Uses the Doctrine DBAL functionality.
+
+* [DB test controller](web/index.php)
+
+
+## Infrastructure Software Versions
+The tests were run with:
+
+* [Silica dev-master](https://github.com/changloong/Silica)
+* [PHP Version 5.4.13](http://www.php.net/) with FPM and APC
+* [nginx 1.4.0](http://nginx.org/)
+* [MySQL 5.5.29](https://dev.mysql.com/)
+
+## Test URLs
+### JSON Encoding Test
+
+http://localhost/json
+
+### Data-Store/Database Mapping Test
+
+http://localhost/db
+
+### Variable Query Test
+    
+http://localhost/db?queries=2

+ 0 - 0
php-silica/__init__.py


+ 12 - 0
php-silica/benchmark_config

@@ -0,0 +1,12 @@
+{
+  "framework": "silica",
+  "tests": [{
+    "raw": {
+      "setup_file": "setup",
+      "db_url": "/db",
+      "query_url": "/db?queries=",
+      "port": 8080,
+      "sort": 64
+    }
+  }]
+}

+ 6 - 0
php-silica/composer.json

@@ -0,0 +1,6 @@
+{
+    "require": {
+        "silica/silica": "dev-master"
+    }
+}
+

+ 128 - 0
php-silica/deploy/nginx.conf

@@ -0,0 +1,128 @@
+#user  nobody;
+worker_processes  8;
+
+#error_log  logs/error.log;
+#error_log  logs/error.log  notice;
+#error_log  logs/error.log  info;
+
+#pid        logs/nginx.pid;
+
+
+events {
+    worker_connections  1024;
+}
+
+
+http {
+    include       /usr/local/nginx/conf/mime.types;
+    default_type  application/octet-stream;
+
+    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
+    #                  '$status $body_bytes_sent "$http_referer" '
+    #                  '"$http_user_agent" "$http_x_forwarded_for"';
+
+    #access_log  logs/access.log  main;
+
+    sendfile        on;
+    #tcp_nopush     on;
+
+    #keepalive_timeout  0;
+    keepalive_timeout  65;
+
+    #gzip  on;
+
+    server {
+        listen       8080;
+        server_name  localhost;
+
+        #charset koi8-r;
+
+        #access_log  logs/host.access.log  main;
+
+        #location / {
+        #    root   html;
+        #    index  index.html index.htm;
+        #}
+
+        #error_page  404              /404.html;
+
+        # redirect server error pages to the static page /50x.html
+        #
+        #error_page   500 502 503 504  /50x.html;
+        #location = /50x.html {
+        #    root   html;
+        #}
+
+        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
+        #
+        #location ~ \.php$ {
+        #    proxy_pass   http://127.0.0.1;
+        #}
+
+        root /home/ubuntu/FrameworkBenchmarks/php-silica/web/;
+        index  index.php;
+
+        location / {
+            try_files $uri @rewriteapp;
+        }
+		
+        location @rewriteapp {
+                rewrite ^(.*)$ /app.php/$1 last;
+        }
+
+        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
+        #
+        location ~ \.php$ {
+            fastcgi_pass   127.0.0.1:9001;
+            fastcgi_index  index.php;
+#            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
+            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
+            include        /usr/local/nginx/conf/fastcgi_params;
+        }
+
+        # deny access to .htaccess files, if Apache's document root
+        # concurs with nginx's one
+        #
+        #location ~ /\.ht {
+        #    deny  all;
+        #}
+    }
+
+
+    # another virtual host using mix of IP-, name-, and port-based configuration
+    #
+    #server {
+    #    listen       8000;
+    #    listen       somename:8080;
+    #    server_name  somename  alias  another.alias;
+
+    #    location / {
+    #        root   html;
+    #        index  index.html index.htm;
+    #    }
+    #}
+
+
+    # HTTPS server
+    #
+    #server {
+    #    listen       443;
+    #    server_name  localhost;
+
+    #    ssl                  on;
+    #    ssl_certificate      cert.pem;
+    #    ssl_certificate_key  cert.key;
+
+    #    ssl_session_timeout  5m;
+
+    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
+    #    ssl_ciphers  HIGH:!aNULL:!MD5;
+    #    ssl_prefer_server_ciphers   on;
+
+    #    location / {
+    #        root   html;
+    #        index  index.html index.htm;
+    #    }
+    #}
+
+}

+ 9 - 0
php-silica/deploy/php-silica

@@ -0,0 +1,9 @@
+<VirtualHost *:8080>
+  Alias /php-silex/ "/home/ubuntu/FrameworkBenchmarks/php-silica/web/"
+  <Directory /home/ubuntu/FrameworkBenchmarks/php-silica/web/>
+          Options Indexes FollowSymLinks MultiViews
+          #AllowOverride None
+          Order allow,deny
+          allow from all
+  </Directory>
+</VirtualHost>

+ 35 - 0
php-silica/setup.py

@@ -0,0 +1,35 @@
+
+import subprocess
+import sys
+import setup_util
+from os.path import expanduser
+
+home = expanduser("~")
+
+def start(args):
+  setup_util.replace_text("php-silex/web/index.php", "192.168.100.102", "" + args.database_host + "")
+  setup_util.replace_text("php-silex/deploy/php-silica", "\".*\/FrameworkBenchmarks", "\"" + home + "/FrameworkBenchmarks")
+  setup_util.replace_text("php-silex/deploy/php-silica", "Directory .*\/FrameworkBenchmarks", "Directory " + home + "/FrameworkBenchmarks")
+  setup_util.replace_text("php-silex/deploy/nginx.conf", "root .*\/FrameworkBenchmarks", "root " + home + "/FrameworkBenchmarks")
+
+  try:
+    #subprocess.check_call("sudo cp cake/deploy/cake /etc/apache2/sites-available/", shell=True)
+    #subprocess.check_call("sudo a2ensite cake", shell=True)
+    #subprocess.check_call("sudo chown -R www-data:www-data cake", shell=True)
+    #subprocess.check_call("sudo /etc/init.d/apache2 start", shell=True)
+    subprocess.check_call("composer.phar install", shell=True, cwd="php-silica")        
+    subprocess.check_call("sudo php-fpm --fpm-config config/php-fpm.conf -g " + home + "/FrameworkBenchmarks/php-silica/deploy/php-fpm.pid", shell=True)
+    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/php-silica/deploy/nginx.conf", shell=True)
+    return 0
+  except subprocess.CalledProcessError:
+    return 1
+def stop():
+  try:
+    subprocess.call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True)
+    subprocess.call("sudo kill -QUIT $( cat php-silica/deploy/php-fpm.pid )", shell=True)
+    #subprocess.check_call("sudo a2dissite cake", shell=True)
+    #subprocess.check_call("sudo /etc/init.d/apache2 stop", shell=True)
+    #subprocess.check_call("sudo chown -R $USER:$USER cake", shell=True)    
+    return 0
+  except subprocess.CalledProcessError:
+    return 1

+ 8 - 0
php-silica/web/.htaccess

@@ -0,0 +1,8 @@
+# /web/.htaccess
+<IfModule mod_rewrite.c>
+    Options -MultiViews
+
+    RewriteEngine On
+    RewriteCond %{REQUEST_FILENAME} !-f
+    RewriteRule ^ index.php [L]
+</IfModule>

+ 51 - 0
php-silica/web/app.php

@@ -0,0 +1,51 @@
+<?php
+
+error_reporting(-1);
+
+require_once __DIR__ . '/../vendor/silica/silica/src/Silica/Application.php' ;
+
+$app = new Silica\Application();
+
+$app
+->share('pdo', function($app) {
+    $pdo    = new PDO('mysql::host=192.168.100.102;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', array(
+				PDO::ATTR_PERSISTENT => true ,
+           ) ) ;
+    return $pdo ;
+})
+>get('/json', function() {
+	echo json_encode(array("message" => "Hello World!"));
+}) 
+>get('/db', function() use ($app) {
+	
+	$query_count = 1;
+	if (TRUE === isset($_GET['queries'])) {
+	  $query_count = $_GET['queries'];
+	}
+
+	// Create an array with the response string.
+	$arr = array();
+	$id = mt_rand(1, 10000);
+
+	// Define query
+	$statement = $app['pdo']->prepare('SELECT randomNumber FROM World WHERE id = :id');
+	$statement->bindParam(':id', $id, PDO::PARAM_INT);
+
+	// For each query, store the result set values in the response array
+	while (0 < $query_count--) {
+	  $statement->execute();
+  
+	  // Store result in array.
+	  $arr[] = array('id' => $id, 'randomNumber' => $statement->fetchColumn());
+	  $id = mt_rand(1, 10000);
+	}
+
+	// Use the PHP standard JSON encoder.
+	// http://www.php.net/manual/en/function.json-encode.php
+	echo json_encode($arr);
+})
+>run() ;
+
+
+
+