Browse Source

Updated code as per the instruction given in the site

Sanjoy Dey 10 years ago
parent
commit
ae0837cdca

+ 13 - 11
frameworks/PHP/php-cygnite/apps/controllers/BenchController.php

@@ -3,6 +3,7 @@ namespace Apps\Controllers;
 
 use Cygnite\Mvc\Controller\AbstractBaseController;
 use Apps\Models\Fortune;
+use Apps\Models\World;
 
 class BenchController extends AbstractBaseController
 {
@@ -16,21 +17,22 @@ class BenchController extends AbstractBaseController
         echo 'Hello World!';
     }
 
-    public function plaintextAction()
+    public function dbAction($queries = 1)
     {
-        header("Content-Type: text/plain;");
-        echo 'Hello, World!';
-    }
+        $worlds = array();
+        $world = null;
 
-    public function jsonAction()
-    {
-        header('Content-type: application/json');
-        echo json_encode(array('message'=>'Hello, World!'));
-    }
+        for ($i = 0; $i < $queries; ++$i) {
+            $world = World::find(mt_rand(1, 10000));
+            $worlds[] = $world->asArray();
+        }
 
-    public function dbAction()
-    {
+        if ($queries == 1) {
+            $worlds = $worlds[0];
+        }
 
+        header('Content-type: application/json');
+        echo json_encode($worlds);
     }
 
     public function fortunesAction()

+ 24 - 0
frameworks/PHP/php-cygnite/apps/models/World.php

@@ -0,0 +1,24 @@
+<?php 
+namespace Apps\Models;
+
+use Cygnite\Database\ActiveRecord;
+
+class World extends ActiveRecord
+{
+    //your database connection name
+    protected $database = 'hello_world';
+
+    /*
+     | By default Every model class name used as table name
+     | "User" => 'user'
+     | You can also override the table name here
+     */
+    //protected $tableName = 'users';
+
+    protected $primaryKey = 'id';
+
+    public function __construct()
+    {
+        parent::__construct();
+    }
+}// End of the User Model

+ 22 - 4
frameworks/PHP/php-cygnite/apps/routes.php

@@ -1,5 +1,6 @@
 <?php
 use Cygnite\Foundation\Application;
+use Cygnite\Base\Router\Router;
 
 if (!defined('CF_SYSTEM')) {
     exit('No External script access allowed');
@@ -8,16 +9,33 @@ if (!defined('CF_SYSTEM')) {
 $app = Application::instance();
 
 // Before Router Middle Ware
-$app->router->before('GET', '/{:all}', function ()
+/*$app->router->before('GET', '/{:all}', function ()
 {
    //echo "This site is under maintenance.";exit;
+});*/
+
+$app->router->get('/json', function ()
+{
+    header('Content-type: application/json');
+    echo json_encode(array('message'=>'Hello, World!'));
+});
+
+$app->router->get('/plaintext', function ()
+{
+    header("Content-Type: text/plain;");
+    echo 'Hello, World!';
+});
+
+// Dynamic route: /fortunes
+$app->router->get('/fortunes', function ()
+{
+    Router::call('Bench.fortunes', array());
 });
 
 /*
-// Dynamic route: /hello/cygnite/3222
-$app->router->get('/hello/{:name}/{:digit}', function ($router, $name, $id)
+$app->router->get('/db/{:digit}', function ($router, $id)
 {
-   //Router::call('Home.welcome', array($name, $id));
+    Router::call('Bench.fortunes', array());
 });
 */
 

+ 15 - 16
frameworks/PHP/php-cygnite/composer.json

@@ -10,19 +10,18 @@
             "email": "[email protected]"
         }
     ],
-	"require": {
-		"cygnite/framework": "1.*"
-	},   
-  "autoload": {
-     "classmap": [
-          "apps/controllers",
-          "apps/models",
-          "apps/components" ,
-		  "apps/extensions" 
-     ]
-   },
-   "config": {
-		"preferred-install": "dist"
-	},
-	"minimum-stability": "stable"
-}
+    "require": {
+        "cygnite/framework": "dev-master"
+    },
+    "autoload": {
+        "classmap": [
+            "apps/controllers",
+            "apps/models",
+            "apps/components" ,
+            "apps/extensions"
+        ]
+    },
+    "config": {
+        "preferred-install": "dist"
+    }
+}

+ 133 - 0
frameworks/PHP/php-cygnite/deploy/nginx.conf

@@ -0,0 +1,133 @@
+#user  nobody;
+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;
+
+
+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;
+    access_log off;
+
+    sendfile        on;
+    #tcp_nopush     on;
+
+    #keepalive_timeout  0;
+    keepalive_timeout  65;
+
+    #gzip  on;
+    
+    upstream fastcgi_backend {
+        server 127.0.0.1:9001;
+        keepalive 32;
+    }
+
+    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-cygnite/;
+        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   fastcgi_backend;
+            fastcgi_index  index.php;
+#            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
+            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
+            fastcgi_keep_conn on;
+            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
frameworks/PHP/php-cygnite/deploy/php-cygnite

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

+ 12 - 0
frameworks/PHP/php-cygnite/install.sh

@@ -0,0 +1,12 @@
+#!/bin/bash
+
+export PHP_HOME=${IROOT}/php-5.5.17
+export COMPOSER_HOME=${IROOT}/php-composer
+export PHP_FPM=$PHP_HOME/sbin/php-fpm
+export NGINX_HOME=${IROOT}/nginx
+
+fw_depends php nginx composer
+
+${PHP_HOME}/bin/php ${COMPOSER_HOME}/composer.phar install \
+  --no-interaction --working-dir $TROOT \
+  --no-progress --optimize-autoloader 

+ 15 - 0
frameworks/PHP/php-cygnite/setup.sh

@@ -0,0 +1,15 @@
+#!/bin/bash
+
+export PHP_HOME=${IROOT}/php-5.5.17
+export COMPOSER_HOME=${IROOT}/php-composer
+export PHP_FPM=${PHP_HOME}/sbin/php-fpm
+export NGINX_HOME=${IROOT}/nginx
+
+sed -i 's|127.0.0.1|'"${DBHOST}"'|g' apps/configs/database.php
+sed -i 's|root .*/FrameworkBenchmarks/php-cygnite|root '"${TROOT}"'|g' deploy/nginx.conf
+sed -i 's|/usr/local/nginx/|'"${IROOT}"'/nginx/|g' deploy/nginx.conf
+
+export PATH="${PHP_HOME}/bin:${PHP_HOME}/sbin:$PATH"
+
+$PHP_FPM --fpm-config ${FWROOT}/config/php-fpm.conf -g ${TROOT}/deploy/php-fpm.pid
+${NGINX_HOME}/sbin/nginx -c ${TROOT}/deploy/nginx.conf