Chang Long 12 éve
szülő
commit
e4874825c3

+ 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 ^(.*)$ /index.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>

+ 42 - 0
php-silica/web/index.php

@@ -0,0 +1,42 @@
+<?php
+
+error_reporting(-1);
+
+require_once __DIR__ . '/../vendor/silica/silica/src/Silica/Application.php' ;
+
+$app = new Silica\Application();
+
+$app->share('pdo', function($app) {
+    $options = array(
+                // PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
+                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
+                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ ,
+           );
+    $pdo    = new PDO('mysql::host=192.168.100.102;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', $options ) ;
+    return $pdo ;
+}) ;
+
+$app->get('/json', function() {
+	echo json_encode(array("message" => "Hello World!"));
+}) ;
+
+$app->get('/db', function() use ($app) {
+    $queries =  1 ;
+	if( isset($_GET['queries']) ) {
+		$queries = (int) $_GET['queries'] ;
+	}
+    // possibility for micro enhancement could be the use of SplFixedArray -> http://php.net/manual/de/class.splfixedarray.php
+    $worlds = array();
+
+    for($i = 0; $i < $queries; ++$i) {
+        $worlds[] = $app['db']->fetchAssoc('SELECT * FROM World WHERE id = ?', array(mt_rand(1, 10000)));
+    }
+	echo json_encode( $worlds ) ;
+});
+
+
+$app->run();
+
+
+
+