Browse Source

Merge pull request #1590 from TechEmpower/php-ccf2

Php ccf2
Mike Smith 10 years ago
parent
commit
fcb6fcc34a

+ 1 - 0
.travis.yml

@@ -110,6 +110,7 @@ env:
     - "TESTDIR=PHP/php"
     - "TESTDIR=PHP/php"
     - "TESTDIR=PHP/cygnite-php-framework"
     - "TESTDIR=PHP/cygnite-php-framework"
     - "TESTDIR=PHP/codeigniter"
     - "TESTDIR=PHP/codeigniter"
+    - "TESTDIR=PHP/clancats"
     - "TESTDIR=PHP/php-fatfree"
     - "TESTDIR=PHP/php-fatfree"
     - "TESTDIR=PHP/fuel"
     - "TESTDIR=PHP/fuel"
     - "TESTDIR=PHP/kohana"
     - "TESTDIR=PHP/kohana"

+ 3 - 0
frameworks/PHP/clancats/.bowerrc

@@ -0,0 +1,3 @@
+{
+  "directory": "public/assets/vendor"
+}

+ 12 - 0
frameworks/PHP/clancats/.gitignore

@@ -0,0 +1,12 @@
+public/assets/packtacular/
+CCF/app/config/migrator.json
+CCF/vendor/
+storage/
+.DS_Store
+Thumbs.db
+composer.phar
+composer.lock
+phpunit.xml
+phpunit.phar
+report/
+run

+ 72 - 0
frameworks/PHP/clancats/app/App.php

@@ -0,0 +1,72 @@
+<?php 
+/*
+ *---------------------------------------------------------------
+ * Application Object
+ *---------------------------------------------------------------
+ *
+ * This is your default application object.
+ */
+class App extends CCApp 
+{	
+	/**
+	 * The application name
+	 *
+	 * @var string
+	 */
+	public static $name = 'My Application';
+	
+	/**
+	 * App configuration
+	 *
+	 * @var CCConfig
+	 */
+	public static $config = null;
+	
+	/**
+	 * current user object
+	 *
+	 * @var User
+	 */
+	public static $user = null;
+	
+	/**
+	 * Application initialization.
+	 * do your inital stuff here like getting the current user object ect..
+	 * You can return a CCResponse wich will cancle all other actions 
+	 * if enebaled ( see. main.config -> send_app_wake_response )
+	 *
+	 * @return void | CCResponse
+	 */
+	public static function wake() 
+	{
+		/*
+		 * Start the session by adding the current uri
+		 */
+		//CCSession::set( 'uri', CCServer::uri() );
+		
+		/*
+		 * try to authenticate the user
+		 */
+		//static::$user =& CCAuth::handler()->user;
+		
+		/*
+		 * load the App configuration
+		 */
+		//static::$config = CCConfig::create( 'app' );
+	}
+	
+	/**
+	 * Environment wake
+	 * This is an environment wake they get called if your running
+	 * the application in a special environment like:
+	 *     wake_production
+	 *     wake_phpunit
+	 *     wake_test
+	 *
+	 * @return void | CCResponse
+	 */
+	public static function wake_development() 
+	{	
+		CCProfiler::check( 'App::development - Application finished wake events.' );
+	}
+}

+ 24 - 0
frameworks/PHP/clancats/app/config/database.config.php

@@ -0,0 +1,24 @@
+<?php 
+/*
+ *---------------------------------------------------------------
+ * Database configuration
+ *---------------------------------------------------------------
+ */
+return array(
+	/*
+	 * the default database
+	 */
+	'main' =>  array(
+		// selected database
+		'db'	 => 'hello_world',
+	
+		// driver
+		'driver' => 'mysql',
+	
+		// auth
+		'host'		=> 'localhost',
+		'user' 		=> 'benchmarkdbuser',
+		'pass'		=> 'benchmarkdbpass',
+		'charset'	=> 'utf8'
+	),
+);

+ 27 - 0
frameworks/PHP/clancats/app/config/main.config.php

@@ -0,0 +1,27 @@
+<?php 
+/*
+ *---------------------------------------------------------------
+ * Main CCF configuration
+ *---------------------------------------------------------------
+ *
+ * Take a look at the core main configuration file to see 
+ * what options are around. .../CCF/vendor/clancats/core/config/main.config.php
+ */
+return array(
+	
+	/*
+	 * URL configuration
+	 */
+	'url'	=> array(
+		// if not in the root directory set the path offset.
+		'path'		=> '/',
+	),
+	
+	/*
+	 * Security
+	 */
+	'security' => array(
+		// it is really important that you choose your own one!
+		'salt' => '7Q[„YI[œ1<-2S3Ck[%¼Sz59vQ!sl1aœÃ',
+	),
+);

+ 107 - 0
frameworks/PHP/clancats/app/config/router.config.php

@@ -0,0 +1,107 @@
+<?php 
+/*
+ *---------------------------------------------------------------
+ * Router map configuration
+ *---------------------------------------------------------------
+ *
+ * You can use this configuration to set you default application
+ * routes.
+ */
+return array(
+
+	/*
+	 * Not Found and internal Server Error
+	 */
+	'#404'	=> 'Error@404',
+	'#500'	=> 'Error@500',
+
+	/**
+	 * Plaintext response benchmark
+	 */
+	'plaintext' => function()
+	{
+		$response = CCResponse::create("Hello, World!", 200);
+		$response->header("Content-Type", "text/plain; charset=UTF-8");
+		return $response;
+ 	},
+       	
+	/**
+	 * JSON response benchmark
+	 */
+	'json' => function() 
+	{
+		return CCResponse::create( json_encode(
+			array('message' => 'Hello, World!')
+		), 200 )->header( 'Content-Type', 'application/json' );
+	},
+
+	
+	/**
+	 * DB response benchmark
+	 */
+	'db' => function() 
+	{		
+		$world = DB::select( 'World' )->find( mt_rand(1, 10000) );
+		$world->id = intval($world->id);
+		$world->randomNumber = intval($world->randomNumber);
+		return CCResponse::create( json_encode( $world), 200 )
+			->header( 'Content-Type', 'application/json' );
+	},
+	
+	/**
+	 * Qeuries response benchmark
+	 */
+	'queries' => function() 
+	{		
+		$queries = CCIn::get( 'queries', 1 );
+		if ($queries < 1) {
+			$queries = 1;
+	        }  
+	        if ($queries > 500) {
+			$queries = 500;
+		}	
+                $worlds = array();
+		
+		for($i = 0; $i < $queries; ++$i) 
+		{
+			$world = DB::select( 'World' )->find( mt_rand(1, 10000) );
+			$world->id = intval($world->id);
+			$world->randomNumber = intval($world->randomNumber);
+			$worlds[] = $world;
+		}
+		return CCResponse::create( json_encode( $worlds), 200 )
+			->header( 'Content-Type', 'application/json' );
+	},
+
+	/**
+	 * Updates response benchmark
+	 */
+	'updates' => function() 
+	{		
+		$queries = CCIn::get( 'queries', 1 );
+		if ($queries < 1) {
+			$queries = 1;
+	        }  
+	        if ($queries > 500) {
+			$queries = 500;
+		}	
+                $worlds = array();
+		
+		for($i = 0; $i < $queries; ++$i) 
+		{
+			$id = mt_rand(1, 10000);
+			DB::update( 'World' )
+				->set( 'randomNumber', mt_rand(1, 10000) )
+				->where( 'id', $id )
+				->run(); 
+			$world = DB::select( 'World' )->find( $id );
+			$world->id = intval($world->id);
+			$world->randomNumber = intval($world->randomNumber);
+			$worlds[] = $world;
+		}
+		return CCResponse::create( json_encode( $worlds), 200 )
+			->header( 'Content-Type', 'application/json' );
+	},
+	
+	'fortunes' => 'Bench@fortunes',
+);

+ 33 - 0
frameworks/PHP/clancats/app/controllers/BenchController.php

@@ -0,0 +1,33 @@
+<?php
+class BenchController extends CCController 
+{	
+	/**
+	 * Sign out action
+	 */
+	public function action_fortunes() 
+	{
+		$view = CCView::create( 'bench/fortune' );
+		
+		$fortunes = DB::select( 'Fortune' )->run();
+		
+		$runtimeFortune = new stdClass;
+		$runtimeFortune->id = 0;
+		$runtimeFortune->message = 'Additional fortune added at request time.';
+		
+		$fortunes[] = $runtimeFortune;
+		
+		usort($fortunes, function($left, $right) {
+			if ($left->message === $right->message) {
+				return 0;
+			} else if ($left->message > $right->message) {
+				return 1;
+			} else {
+				return -1;
+			}
+		});
+		
+		$view->fortunes = $fortunes;
+		
+		return CCResponse::create( $view->render() );
+	}
+}

+ 24 - 0
frameworks/PHP/clancats/app/views/bench/fortune.php

@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<title>Fortunes</title>
+</head>
+<body>
+
+<table>
+	<tr>
+		<th>id</th>
+		<th>message</th>
+	</tr>
+
+	<?php foreach($fortunes as $fortune): ?>
+	<tr>
+		<td><?php echo $fortune->id; ?></td>
+		<td><?php echo htmlspecialchars($fortune->message); ?></td>
+	</tr>
+	<?php endforeach; ?>
+
+</table>
+
+</body>
+</html>

+ 28 - 0
frameworks/PHP/clancats/benchmark_config.json

@@ -0,0 +1,28 @@
+{
+  "framework": "clancats",
+  "tests": [{
+	"default": {
+	  "setup_file": "setup",
+	  "plaintext_url": "/plaintext",
+	  "json_url": "/json",
+	  "db_url": "/db",
+	  "query_url": "/queries?queries=",
+	  "update_url": "/updates?queries=",
+	  "fortune_url": "/fortunes",
+	  "port": 8080,
+	  "approach": "Realistic",
+	  "classification": "Fullstack",
+	  "database": "MySQL",
+	  "framework": "clancatsframework",
+	  "language": "PHP",
+	  "orm": "Raw",
+	  "platform": "PHP-FPM",
+	  "webserver": "nginx",
+	  "os": "Linux",
+	  "database_os": "Linux",
+	  "display_name": "clancatsframework",
+	  "notes": "",
+	  "versus": "php"
+	}
+  }]
+}

+ 25 - 0
frameworks/PHP/clancats/composer.json

@@ -0,0 +1,25 @@
+{
+	"name": "clancats/framework",
+	"description": "ClanCats Framework, because your time is precious. HMVC PHP framework.",
+	"homepage": "http://www.clancats.io",
+	"keywords": ["ccf", "framework", "clancats"],
+	"license": "MIT",
+	"require": {
+		"clancats/core": "2.0.*"
+	},
+	"config": {
+		"vendor-dir": "CCF/vendor"
+	},
+	"scripts": {
+		"post-install-cmd": [
+			"php cli phpunit::build"
+		],
+		"post-update-cmd": [
+			"php cli phpunit::build"
+		],
+		"post-create-project-cmd": [
+			"php cli doctor::security_key"
+		]
+	},
+	"minimum-stability": "stable"
+}

+ 43 - 0
frameworks/PHP/clancats/deploy/nginx.conf

@@ -0,0 +1,43 @@
+worker_processes  8;
+
+error_log stderr error;
+
+events {
+	worker_connections  1024;
+}
+
+http {
+	include       /usr/local/nginx/conf/mime.types;
+	default_type  application/octet-stream;
+
+	access_log off;
+
+	sendfile        on;
+	keepalive_timeout  65;
+
+	upstream fastcgi_backend {
+		server 127.0.0.1:9001;
+		keepalive 32;
+	}
+
+	server {
+		listen       8080;
+		server_name  localhost;
+
+		root /home/ubuntu/FrameworkBenchmarks/;
+		index  index.php;
+
+		location / {
+			try_files $uri $uri/ /index.php?$uri&$args;
+		}
+
+		location ~ \.php$ {
+			try_files $uri =404;
+			fastcgi_pass   fastcgi_backend;
+			fastcgi_keep_conn on;
+			fastcgi_index  index.php;
+			fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
+			include        /usr/local/nginx/conf/fastcgi_params;
+		}
+	}
+}

+ 9 - 0
frameworks/PHP/clancats/deploy/php-clancatsframework

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

+ 1 - 0
frameworks/PHP/clancats/deploy/php-fpm.pid

@@ -0,0 +1 @@
+18981

+ 32 - 0
frameworks/PHP/clancats/index.php

@@ -0,0 +1,32 @@
+<?php 
+/*
+ *---------------------------------------------------------------
+ * ClanCatsFramework runner
+ *---------------------------------------------------------------
+ *
+ * This file just loads CCF and all needed resources to run the 
+ * php unit tests. PHPUnit is a really elegant way to make sure 
+ * that everything works how it should.
+ *
+ *---------------------------------------------------------------
+ * Require CCF
+ *---------------------------------------------------------------
+ *
+ * load the framework file wich wil initialize CCF. 
+ */
+require_once __DIR__."/clancatsapp/framework.php";
+
+/*
+ * execute the main request
+ * The main request contains the params of the http header
+ */
+$response = CCRequest::uri( CCServer::uri() )
+    ->perform()
+    ->response();
+
+/*
+ * "send" means actaully printing the response.
+ * If the secound parameter is true the response will 
+ * also set headers
+ */
+$response->send( true );

+ 20 - 0
frameworks/PHP/clancats/install.sh

@@ -0,0 +1,20 @@
+#!/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
+
+cd $TROOT
+rm -fr clancatsapp
+rm -fr CCF
+git clone --branch v2.0.6 https://github.com/ClanCats/Framework.git clancatsapp
+
+cp -r app/ clancatsapp/CCF/
+
+${PHP_HOME}/bin/php ${COMPOSER_HOME}/composer.phar install \
+  --no-interaction --working-dir $TROOT \
+  --no-progress --optimize-autoloader 
+
+cp -r CCF/vendor/ clancatsapp/CCF/

+ 11 - 0
frameworks/PHP/clancats/setup.sh

@@ -0,0 +1,11 @@
+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|localhost|'"${DBHOST}"'|g' index.php
+sed -i 's|root /home/ubuntu/FrameworkBenchmarks|root '"${TROOT}"'|g' deploy/nginx.conf
+sed -i 's|/usr/local/nginx/|'"${IROOT}"'/nginx/|g' deploy/nginx.conf
+
+$PHP_FPM --fpm-config $FWROOT/config/php-fpm.conf -g $TROOT/deploy/php-fpm.pid
+$NGINX_HOME/sbin/nginx -c $TROOT/deploy/nginx.conf