Browse Source

all Lumen tests working except for queries

Keith Newman 10 years ago
parent
commit
b6905c1d29

+ 1 - 0
.travis.yml

@@ -104,6 +104,7 @@ env:
     - "TESTDIR=PHP/php-laravel"
     - "TESTDIR=PHP/limonade"
     - "TESTDIR=PHP/lithium"
+    - "TESTDIR=PHP/lumen"
     - "TESTDIR=PHP/php-micromvc"
     - "TESTDIR=PHP/php-phalcon"
     - "TESTDIR=PHP/php-phalcon-micro"

+ 5 - 0
frameworks/PHP/lumen/.env

@@ -0,0 +1,5 @@
+DB_CONNECTION=mysql
+DB_HOST=localhost
+DB_DATABASE=hello_world
+DB_USERNAME=benchmarkdbuser
+DB_PASSWORD=benchmarkdbpass

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

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

+ 75 - 0
frameworks/PHP/lumen/app/Http/routes.php

@@ -0,0 +1,75 @@
+<?php
+
+function update_world(&$world, $key) {
+	$world->randomNumber = mt_rand(1, 10000);
+}
+
+function compare_fortunes($f1, $f2) {
+	return strcmp ($f1->message, $f2->message);
+}
+
+$app->get("plaintext", function() use ($app) {
+    return response("Hello, World!")->header("Content-Type", "text/plain; charset=utf-8");
+});
+
+$app->get("json", function() use ($app) {
+	return response()->json(["message" => "Hello, World!"]);
+});
+
+$app->get("db", function() use ($app) {
+	$id = mt_rand(1, 10000);
+	$results = DB::select('select * from world where id = ?', [$id]);
+	return response()->json($results[0]);
+});
+
+$app->get("queries/{queries}", function($queries=1) use ($app) {
+	$query_count = $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 = DB::select("select * from world where id= ?", [$id]);
+		$worlds[] = $world[0];
+	}
+
+	return response()->json($worlds);
+});
+
+$app->get("updates/{queries}", function($queries) use($app) {
+	$query_count = $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 = DB::select("select * from world where id= ?", [$id]);
+		$worlds[] = $world[0];
+	}
+
+	array_walk($worlds, "update_world");
+
+	return response()->json($worlds);
+});
+
+$app->get("fortune", function() use ($app) {
+	$fortunes = DB::select("select * from fortune");
+	$new_fortune = new stdClass;
+	$new_fortune->id = 0;
+	$new_fortune->message = "Additional fortune added at request time.";
+	$fortunes[] = $new_fortune;
+	usort($fortunes, "compare_fortunes");
+	return view("fortune", ["fortunes" => $fortunes]);
+});

+ 27 - 0
frameworks/PHP/lumen/benchmark_config.json

@@ -0,0 +1,27 @@
+
+{
+  "framework": "lumen",
+  "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": "Lumen",
+      "language": "PHP",
+      "orm": "Full",
+      "platform": "PHP-FPM",
+      "webserver": "nginx",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Lumen"
+    }
+  }]
+}

+ 22 - 0
frameworks/PHP/lumen/bootstrap/app.php

@@ -0,0 +1,22 @@
+<?php
+require_once __DIR__.'/../vendor/autoload.php';
+
+Dotenv::load(__DIR__.'/../');
+
+$app = new Laravel\Lumen\Application;
+$app->withFacades();
+
+$app->singleton(
+    'Illuminate\Contracts\Debug\ExceptionHandler',
+    'App\Exceptions\Handler'
+);
+
+$app->singleton(
+    'Illuminate\Contracts\Console\Kernel',
+    'App\Console\Kernel'
+);
+
+require __DIR__.'/../app/Http/routes.php';
+
+return $app;
+

+ 6 - 0
frameworks/PHP/lumen/composer.json

@@ -0,0 +1,6 @@
+{
+   "require": {
+   	"laravel/lumen" : "5.0.1"
+   }
+}
+

+ 42 - 0
frameworks/PHP/lumen/deploy/nginx.conf

@@ -0,0 +1,42 @@
+worker_processes  8;
+
+error_log stderr error;
+
+events {
+    worker_connections  1024;
+}
+
+http {
+    include       /home/knewman/FrameworkBenchmarks/installs/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/knewman/FrameworkBenchmarks/frameworks/PHP/lumen/public;
+        index  index.php;
+
+        location / {
+            try_files $uri $uri/ /index.php?query_string;
+        }
+
+        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        /home/knewman/FrameworkBenchmarks/installs/nginx/conf/fastcgi_params;
+        }
+
+    }
+}

+ 10 - 0
frameworks/PHP/lumen/install.sh

@@ -0,0 +1,10 @@
+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 

+ 6 - 0
frameworks/PHP/lumen/public/index.php

@@ -0,0 +1,6 @@
+<?php
+
+$app = require __DIR__.'/../bootstrap/app.php';
+
+$app->run();
+

+ 19 - 0
frameworks/PHP/lumen/resources/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>" . htmlspecialchars($f->message) . "</td></tr>");
+}
+?>
+</table>
+</body>
+</html>

+ 13 - 0
frameworks/PHP/lumen/setup.sh

@@ -0,0 +1,13 @@
+
+#!/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' public/index.php
+sed -i 's|root .*/FrameworkBenchmarks/lumen/public|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