Browse Source

Merge pull request #1522 from TechEmpower/php-limonade

Added tests for PHP limonade framework
Brittany Mazza 10 years ago
parent
commit
936705af46

+ 1 - 0
.travis.yml

@@ -102,6 +102,7 @@ env:
     - "TESTDIR=PHP/fuel"
     - "TESTDIR=PHP/fuel"
     - "TESTDIR=PHP/kohana"
     - "TESTDIR=PHP/kohana"
     - "TESTDIR=PHP/php-laravel"
     - "TESTDIR=PHP/php-laravel"
+    - "TESTDIR=PHP/limonade"
     - "TESTDIR=PHP/lithium"
     - "TESTDIR=PHP/lithium"
     - "TESTDIR=PHP/php-micromvc"
     - "TESTDIR=PHP/php-micromvc"
     - "TESTDIR=PHP/php-phalcon"
     - "TESTDIR=PHP/php-phalcon"

+ 2 - 0
frameworks/PHP/limonade/.gitignore

@@ -0,0 +1,2 @@
+vendor
+deploy/php-fpm.pid

+ 26 - 0
frameworks/PHP/limonade/benchmark_config.json

@@ -0,0 +1,26 @@
+{
+  "framework": "limonade",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "db_url": "/db",
+      "query_url": "/queries/",
+      "fortune_url": "/fortune",
+      "update_url": "/updates/",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Micro",
+      "database": "MySQL",
+      "framework": "Limonade",
+      "language": "PHP",
+      "orm": "Full",
+      "platform": "PHP-FPM",
+      "webserver": "nginx",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Limonade"
+    }
+  }]
+}

+ 7 - 0
frameworks/PHP/limonade/composer.json

@@ -0,0 +1,7 @@
+{
+   "require": {
+   	"sofadesign/limonade" : "dev-master",
+   	"php-activerecord/php-activerecord" : "1.1.2"
+   }
+}
+

+ 46 - 0
frameworks/PHP/limonade/deploy/nginx.conf

@@ -0,0 +1,46 @@
+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/limonade/;
+        index  index.php;
+
+        location / {
+            try_files $uri $uri/ @rewrite;
+        }
+
+        location @rewrite {
+            rewrite ^/(.*)$ /index.php?u=$1&$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;
+        }
+
+    }
+}

+ 105 - 0
frameworks/PHP/limonade/index.php

@@ -0,0 +1,105 @@
+<?php
+require_once "vendor/sofadesign/limonade/lib/limonade.php";
+require_once "vendor/php-activerecord/php-activerecord/ActiveRecord.php";
+
+function configure() {
+	$cfg = ActiveRecord\Config::instance();
+	$cfg->set_model_directory("models");
+	$cfg->set_connections(array(
+		"development" => "mysql://benchmarkdbuser:benchmarkdbpass@localhost/hello_world?charset=utf8"));
+
+option("bas_url", "/");
+}
+
+dispatch("/plaintext", "plaintext");
+function plaintext() {
+	header('Content-Type: text/plain; charset=utf-8');
+	return txt("Hello, World!");
+}
+
+dispatch("/json", "jsonHandler");
+function jsonHandler() {
+	header('Content-Type: application/json; charset=utf-8');
+	$arr = array("message" => "Hello, World!");
+	return json($arr);
+}
+
+dispatch("/db", "db");
+function db() {
+	$id = mt_rand(1, 10000);
+	$test = World::find($id);
+	return json($test->to_array());
+}
+
+dispatch("/queries/:queries", "queries");
+function queries() {
+	header('Content-Type: application/json; charset=utf-8');
+	$query_count = params("queries");
+	if ($query_count < 1) {
+		$query_count = 1;
+	}
+	if ($query_count > 500) {
+		$query_count = 500;
+	}
+	
+	$worlds = array();
+
+	for ($i = 0; $i < $query_count; $i++) {
+		$id = mt_rand(1, 10000);
+		$world = World::find($id);
+		$worlds[] = $world->to_array();
+	}
+
+	return json($worlds);
+
+}
+
+function update_world(&$world, $key) {
+	$world["randomnumber"] = mt_rand(1, 10000);
+}
+
+dispatch("/updates/:queries", "updates");
+function updates() {
+	header('Content-Type: application/json; charset=utf-8');
+	$query_count = params("queries");
+	if ($query_count < 1) {
+		$query_count = 1;
+	}
+	if ($query_count > 500) {
+		$query_count = 500;
+	}
+
+	$worlds = array();
+
+	for ($i = 0; $i < $query_count; $i++) {
+		$id = mt_rand(1, 10000);
+		$world = World::find($id);
+		$worlds[] = $world->to_array();
+	}
+
+	array_walk($worlds, "update_world");
+
+	return json($worlds);
+}
+
+function fortune_to_array(&$fortune, $key) {
+	$fortune->message = htmlspecialchars($fortune->message);
+	$fortune = $fortune->to_array();
+}
+
+function compare_fortunes($f1, $f2) {
+	return strcmp($f1["message"], $f2["message"]);
+}
+
+dispatch("/fortune", "fortune");
+function fortune() {
+	header('Content-Type: text/html; charset=utf-8');
+	$fortunes = Fortune::all();
+	array_walk($fortunes, "fortune_to_array");
+	$fortunes[] = array("id"=>0, "message"=> "Additional fortune added at request time.");
+	usort($fortunes, "compare_fortunes");
+	return render("fortune.php", null, array("fortunes" => $fortunes));
+}
+
+run();
+?>

+ 11 - 0
frameworks/PHP/limonade/install.sh

@@ -0,0 +1,11 @@
+#!/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 

+ 5 - 0
frameworks/PHP/limonade/models/Fortune.php

@@ -0,0 +1,5 @@
+<?php
+class Fortune extends ActiveRecord\Model {
+	static $table_name = "Fortune";
+}
+?>

+ 5 - 0
frameworks/PHP/limonade/models/World.php

@@ -0,0 +1,5 @@
+<?php
+class World extends ActiveRecord\Model {
+	static $table_name = "World";
+}
+?>

+ 12 - 0
frameworks/PHP/limonade/setup.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
+
+sed -i 's|localhost|'"${DBHOST}"'|g' index.php
+sed -i 's|root .*/FrameworkBenchmarks/limonade|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

+ 19 - 0
frameworks/PHP/limonade/views/fortune.php

@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Fortunes</title>
+</head>
+<body>
+<table>
+<tr>
+<th>id</th>
+<th>message</th>
+</tr>
+<?php
+foreach($fortunes as $f) {
+	echo ("<tr><td>" . $f["id"] . "</td><td>" . $f["message"] . "</td></tr>");
+}
+?>
+</table>
+</body>
+</html>