Browse Source

Initial commit for Phalcon

Skamander 12 years ago
parent
commit
1c11dfbe45

+ 9 - 0
php-phalcon/.gitignore

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

+ 36 - 0
php-phalcon/README.md

@@ -0,0 +1,36 @@
+# Phalcon PHP Benchmarking Test
+
+This is the Phalcon 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](app/controllers/BenchController.php)
+
+
+### Data-Store/Database Mapping Test
+Uses the built-in ORM of Phalcon PHP
+
+* [DB test controller](app/controllers/BenchController.php)
+
+
+## Infrastructure Software Versions
+The tests were run with:
+
+* [Phalcon 1.0.0](http://phalconphp.com/)
+* [PHP Version 5.4.13](http://www.php.net/) with FPM, APC and Phalcon extension
+* [nginx 1.2.7](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-phalcon/__init__.py


+ 18 - 0
php-phalcon/app/config/config.php

@@ -0,0 +1,18 @@
+<?php
+
+return new \Phalcon\Config(array(
+    'database'     => array(
+        'adapter'  => 'Mysql',
+        'host'     => '192.168.100.102',
+        'username' => 'benchmarkdbuser',
+        'password' => 'benchmarkdbpass',
+        'name'     => 'hello_world',
+    ),
+    'application' => array(
+        'controllersDir' => __DIR__ . '/../../app/controllers/',
+        'modelsDir'      => __DIR__ . '/../../app/models/',
+        'viewsDir'       => __DIR__ . '/../../app/views/',
+        'routes'         => __DIR__ . '/../../app/config/routes.php',
+        'baseUri'        => '/',
+    )
+));

+ 16 - 0
php-phalcon/app/config/routes.php

@@ -0,0 +1,16 @@
+<?php
+
+$router = new Phalcon\Mvc\Router();
+
+$router->add('/json', array(
+    'controller' => 'bench',
+    'action' => 'json',
+));
+
+// Handles "/db" as well as "/db?queries={queries}"
+$router->add('/db', array(
+    'controller' => 'bench',
+    'action' => 'db',
+));
+
+return $router;

+ 40 - 0
php-phalcon/app/controllers/BenchController.php

@@ -0,0 +1,40 @@
+<?php
+
+class BenchController extends \Phalcon\Mvc\Controller
+{
+    public function initialize()
+    {
+        $this->view->disable();
+    }
+
+    public function jsonAction() {
+        return $this->sendContentAsJson(array(
+            'message' => 'Hello World!'
+        ));
+    }
+
+    public function dbAction() {
+        $queries = $this->getQueryOrDefault('queries', 1);
+        $worlds = array();
+
+        for ($i = 0; $i < $queries; ++$i) {
+            $worlds[] = Worlds::findFirst(mt_rand(1, 10000));
+        }
+
+        return $this->sendContentAsJson($worlds);
+    }
+
+    private function getQueryOrDefault($query, $default) {
+        return $this->request->getQuery($query) !== null
+            ? $this->request->getQuery($query)
+            : $default;
+    }
+
+    private function sendContentAsJson($content) {
+        $response = new Phalcon\Http\Response();
+        $response->setStatusCode(200, "OK");
+        $response->setHeader("Content-Type", "application/json");
+        $response->setContent(json_encode($content));
+        return $response;
+    }
+}

+ 9 - 0
php-phalcon/app/controllers/IndexController.php

@@ -0,0 +1,9 @@
+<?php
+
+class IndexController extends \Phalcon\Mvc\Controller
+{
+    public function indexAction()
+    {
+        echo "<h1>Wrong controller for this benchmark!</h1>";
+    }
+}

+ 13 - 0
php-phalcon/app/models/Worlds.php

@@ -0,0 +1,13 @@
+<?php
+
+
+class Worlds extends \Phalcon\Mvc\Model
+{
+    public $id;
+
+    public $randomNumber;
+
+    public function getSource() {
+        return "World";
+    }
+}

+ 13 - 0
php-phalcon/benchmark_config

@@ -0,0 +1,13 @@
+{
+  "framework": "Phalcon",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/db?queries=",
+      "port": 8080,
+      "sort": 70
+    }
+  }]
+}

+ 125 - 0
php-phalcon/deploy/nginx.conf

@@ -0,0 +1,125 @@
+#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-phalcon/public/;
+        index  index.php;
+
+        location / {
+            try_files $uri $uri/ /index.php?$uri&$args;
+        }
+
+        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
+        #
+        location ~ \.php$ {
+            try_files $uri =404;
+            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-phalcon/deploy/php-phalcon

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

+ 6 - 0
php-phalcon/public/.htaccess

@@ -0,0 +1,6 @@
+<IfModule mod_rewrite.c>
+    RewriteEngine On
+    RewriteCond %{REQUEST_FILENAME} !-d
+    RewriteCond %{REQUEST_FILENAME} !-f
+    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
+</IfModule>

+ 46 - 0
php-phalcon/public/index.php

@@ -0,0 +1,46 @@
+<?php
+
+try {
+    // Load the config
+    $config = include(__DIR__."/../app/config/config.php");
+
+    // Register an autoloader
+    $loader = new \Phalcon\Loader();
+    $loader->registerDirs(array(
+        $config->application->controllersDir,
+        $config->application->modelsDir
+    ))->register();
+
+    // Create a DI
+    $di = new Phalcon\DI\FactoryDefault();
+
+    // Setting up the router
+    $di->set('router', function() use ($config) {
+        return include($config->application->routes);
+    });
+
+    // Setting up the view component (seems to be required even when not used)
+    $di->set('view', function() use ($config) {
+        $view = new \Phalcon\Mvc\View();
+        $view->setViewsDir($config->application->viewsDir);
+        return $view;
+    });
+
+    // Setting up the database connection
+    $di->set('db', function() use ($config) {
+        return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
+            "host"     => $config->database->host,
+            "username" => $config->database->username,
+            "password" => $config->database->password,
+            "dbname"   => $config->database->name
+        ));
+    });
+
+    // Handle the request
+    $application = new \Phalcon\Mvc\Application();
+    $application->setDI($di);
+    echo $application->handle()->getContent();
+
+} catch(\Phalcon\Exception $e) {
+    echo "PhalconException: ", $e->getMessage();
+}

+ 26 - 0
php-phalcon/setup.py

@@ -0,0 +1,26 @@
+import subprocess
+import sys
+import setup_util
+from os.path import expanduser
+
+home = expanduser("~")
+
+def start(args):
+  setup_util.replace_text("php-phalcon/app/config/config.php", "localhost", ""+ args.database_host +"")
+  setup_util.replace_text("php-phalcon/deploy/nginx.conf", "root .*\/FrameworkBenchmarks", "root " + home + "/FrameworkBenchmarks")
+
+  try:
+    subprocess.check_call("sudo chown -R www-data:www-data php-phalcon", shell=True)
+    subprocess.check_call("sudo php-fpm --fpm-config config/php-fpm.conf -g " + home + "/FrameworkBenchmarks/php-phalcon/deploy/php-fpm.pid", shell=True)
+    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/php-phalcon/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-phalcon/deploy/php-fpm.pid )", shell=True)
+    subprocess.check_call("sudo chown -R $USER:$USER php-phalcon", shell=True)
+    return 0
+  except subprocess.CalledProcessError:
+    return 1