Browse Source

Cakephp php7 (#3026)

* Add PHP 7 test, and update CakePHP 2.10 version

* Fix fortune response and encoding

* Update multi-query and single-query tests

* Add updates test for CakePHP 2.10

* Update CakePHP readme

* Better use of CakePHP for plaintext test

* Restore config

* Update setup.sh

* Fix webroot config

* Make DB connection UTF8 again
Walther Lalk 7 years ago
parent
commit
ddebae0442

+ 12 - 6
frameworks/PHP/cakephp/README.md

@@ -18,25 +18,31 @@ Uses the CakePHP Model functionality.
 ## Infrastructure Software Versions
 The tests were run with:
 
-* [Cake Version 2.10.3](https://cakephp.org/)
-* [PHP Version 5.6.32](http://www.php.net/) with FPM and APC
+* [Cake Version 2.10.4](https://cakephp.org/)
+* [PHP Version 5.6.30](http://www.php.net/) with FPM and APC
+* [PHP Version 7.1.4](http://www.php.net/) with FPM and Opcache
 * [nginx 1.12.0](http://nginx.org/)
 * [MySQL 5.7.19](https://dev.mysql.com/)
 
 Cake Debug mode is set to 0 in [core.php](app/Config/core.php), as
 appropriate for a production deployment.
 
-To support the Cake JsonView, we also made a [routes configuration change](app/Config/routes.php).
+To support the Cake JsonView and use the recommended URLs, 
+we also made a [routes configuration change](app/Config/routes.php).
 
 ## Test URLs
 ### JSON Encoding Test
 
-http://localhost/index.php/json.json
+http://localhost/index.php/json
 
 ### Data-Store/Database Mapping Test
 
-http://localhost/index.php/world.json
+http://localhost/index.php/db
 
 ### Variable Query Test
     
-http://localhost/index.php/world.json?queries=2
+http://localhost/index.php/queries?queries=2
+
+### Variable Update Test
+
+http://localhost/index.php/updates?queries=2

+ 2 - 2
frameworks/PHP/cakephp/app/Config/core.php

@@ -118,7 +118,7 @@ Configure::write('App.baseUrl', env('SCRIPT_NAME'));
  * Turn off all caching application-wide.
  *
  */
-	//Configure::write('Cache.disable', true);
+	Configure::write('Cache.disable', true);
 
 /**
  * Enable cache checking.
@@ -257,7 +257,7 @@ if (Configure::read('debug') >= 1) {
 }
 
 // Prefix each application on the same server with a different string, to avoid Memcache and APC conflicts.
-$prefix = 'myapp_';
+$prefix = 'cakephp2_';
 
 // NOTE: There is currently no implementation of redis so commenting out this configuration for now. This
 // *may* have also been in violation of the rules of some of the database tests.

+ 9 - 13
frameworks/PHP/cakephp/app/Config/routes.php

@@ -20,20 +20,16 @@
  * @since         CakePHP(tm) v 0.2.9
  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
  */
-/**
- * Here, we are connecting '/' (base path) to controller called 'Pages',
- * its action called 'display', and we pass a param to select the view file
- * to use (in this case, /app/View/Pages/home.ctp)...
- */
-	Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
-/**
- * ...and connect the rest of 'Pages' controller's urls.
- */
-	Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
 
-        // Needed to enable JsonView
-        // http://book.cakephp.org/2.0/en/views/json-and-xml-views.html#enabling-data-views-in-your-application
-        Router::parseExtensions('json');
+	// Needed to enable JsonView
+	// http://book.cakephp.org/2.0/en/views/json-and-xml-views.html#enabling-data-views-in-your-application
+	Router::parseExtensions('json');
+
+	Router::connect('/fortunes', ['controller' => 'Fortunes', 'action' => 'index']);
+
+	Router::connect('/db', ['controller' => 'World', 'action' => 'query']);
+	Router::connect('/queries', ['controller' => 'World', 'action' => 'index']);
+	Router::connect('/updates', ['controller' => 'World', 'action' => 'updates']);
 
 /**
  * Load all plugin routes.  See the CakePlugin documentation on

+ 2 - 1
frameworks/PHP/cakephp/app/Controller/FortunesController.php

@@ -4,13 +4,14 @@ App::uses('AppController', 'Controller');
 
 class FortunesController extends AppController {
 
+	public $modelClass = 'Fortune';
+
 	public function index() {
 		// use full view stack as encouraged by test rules
 		$this->layout = 'benchmark';
 		$this->set('title_for_layout', 'Fortunes');
 
 		// using ORM instead of raw SQL
-		$this->loadModel('Fortune');
 		$results = $this->Fortune->find('all');
 
 		// stuffing in the dynamic data

+ 1 - 1
frameworks/PHP/cakephp/app/Controller/JsonController.php

@@ -13,6 +13,6 @@ class JsonController extends AppController {
     // http://book.cakephp.org/2.0/en/views/json-and-xml-views.html
     $this->set('message', "Hello, World!");
     $this->set('_serialize', array('message'));
+  	$this->RequestHandler->renderAs($this, 'json');
   }
 }
-?>

+ 5 - 3
frameworks/PHP/cakephp/app/Controller/PlaintextController.php

@@ -6,8 +6,10 @@ class PlaintextController extends AppController {
 
 	public function index() {
 		$this->autoRender = false;
-		header("Content-type: text/plain");
-		echo 'Hello, World!';
+		$this->response->type('text');
+		$this->response->body('Hello, World!');
+
+		return $this->response;
 
 		/*
 		 * Because this test is focused on routing we don't involve the view.
@@ -21,4 +23,4 @@ class PlaintextController extends AppController {
 
 		 */
 	}
-}
+}

+ 56 - 37
frameworks/PHP/cakephp/app/Controller/WorldController.php

@@ -8,55 +8,74 @@ class WorldController extends AppController {
   // http://book.cakephp.org/2.0/en/views/json-and-xml-views.html#enabling-data-views-in-your-application
   public $components = array('RequestHandler');
 
-  public function index() {
+  protected function _getQueryCount()
+  {
+	  // Read number of queries to run from URL parameter
+	  // http://book.cakephp.org/2.0/en/controllers/request-response.html#accessing-request-parameters
+	  $query_count = $this->request->query('queries');
 
-    // Read number of queries to run from URL parameter
-    // http://book.cakephp.org/2.0/en/controllers/request-response.html#accessing-request-parameters
-    $query_count = $this->request->query('queries');
-    $should_return_array = True;
-    if ($query_count == null) {
-      $query_count = 1;
-      $should_return_array = False;
-    }
-    $query_count = intval($query_count);
-    if ($query_count == 0) {
-      $query_count = 1;
-    } elseif ($query_count > 500) {
-      $query_count = 500;
-    }
+	  $query_count = (int)$query_count;
+	  if ($query_count === 0) {
+		  $query_count = 1;
+	  } elseif ($query_count > 500) {
+		  $query_count = 500;
+	  }
+
+	  return $query_count;
+  }
 
+  public function index() {
     // Create an array with the response string.
-    $arr = array();
+    $worlds = array();
 
+    $query_count = $this->_getQueryCount();
     // For each query, store the result set values in the response array
     for ($i = 0; $i < $query_count; $i++) {
-      // Choose a random row
-      // http://www.php.net/mt_rand
-      $id = mt_rand(1, 10000);
-
-      // Retrieve a model by ID
-      // http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#find
-      $world = $this->World->find('first', array('conditions' => array('id' => $id)));
-      // Cast numbers to int so they don't get quoted in JSON
-      $result = $world['World'];
-      $result['id'] = (int) $result['id'];
-      $result['randomNumber'] = (int) $result['randomNumber'];
-      // Store result in array.
-      $arr[] = array("id" => $result['id'], "randomNumber" => $result['randomNumber']);
+      	// Retrieve a model by ID
+      	// http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#find
+		$worlds[] = $this->World->find('randomId');
     }
 
-    # Return either one object or a json list
-    if ($should_return_array == False) {
-      $this->set('worlds', $arr[0]);
-    } else {
-      $this->set('worlds', $arr);  
-    }
+    # Return json list
+  	$this->set('worlds', $worlds);
 
     // Use the CakePHP JSON View
     // http://book.cakephp.org/2.0/en/views/json-and-xml-views.html
     $this->set('_serialize', 'worlds');
+	$this->RequestHandler->renderAs($this, 'json');
   }
 
-}
-?>
+  public function query()
+  {
+  	$world = $this->World->find('randomId');
 
+  	$this->set('world', $world);
+  	$this->set('_serialize', 'world');
+  	$this->RequestHandler->renderAs($this, 'json');
+  }
+
+  public function updates()
+  {
+	  // Create an array with the response string.
+	  $worlds = [];
+
+	  $query_count = $this->_getQueryCount();
+	  // For each query, store the result set values in the response array
+	  for ($i = 0; $i < $query_count; $i++) {
+		  // Retrieve a model by ID
+		  // http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#find
+		  $world = $this->World->find('randomId');
+		  $world['randomNumber'] = mt_rand(1, 10000);
+		  $this->World->save(['World' => $world]);
+		  $worlds[] = $world;
+	  }
+
+	  # Return json list
+	  $this->set('worlds', $worlds);
+
+	  // Use the CakePHP JSON View
+	  // http://book.cakephp.org/2.0/en/views/json-and-xml-views.html
+	  $this->set('_serialize', 'worlds');
+	  $this->RequestHandler->renderAs($this, 'json');
+  }
+}

+ 21 - 3
frameworks/PHP/cakephp/app/Model/World.php

@@ -1,5 +1,23 @@
 <?php
-class World extends AppModel {
-  public $useTable = 'World'; // This model uses a database table 'World'
-  public $primaryKey = 'id';
+
+class World extends AppModel
+{
+	public $useTable = 'World'; // This model uses a database table 'World'
+	public $primaryKey = 'id';
+	public $findMethods = ['randomId' => true];
+
+	protected function _findRandomId($state, $query, $results = array())
+	{
+		if ($state === 'before') {
+			// Choose a random row
+			// http://www.php.net/mt_rand
+			$id = mt_rand(1, 10000);
+			$query['conditions']['id'] = $id;
+			$query['limit'] = 1;
+
+			return $query;
+		}
+
+		return $results[0]['World'];
+	}
 }

+ 2 - 4
frameworks/PHP/cakephp/app/View/Layouts/benchmark.ctp

@@ -1,11 +1,9 @@
 <!DOCTYPE html>
 <html>
 <head>
-	<title>
-		<?php echo $title_for_layout; ?>
-	</title>
+<title><?php echo $title_for_layout; ?></title>
 </head>
 <body>
-	<?php echo $this->fetch('content'); ?>
+<?php echo $this->fetch('content'); ?>
 </body>
 </html>

+ 30 - 5
frameworks/PHP/cakephp/benchmark_config.json

@@ -3,11 +3,36 @@
   "tests": [{
     "default": {
       "setup_file": "setup",
-      "json_url": "/json.json",
-      "db_url": "/world/index.json",
-      "query_url": "/world.json?queries=",
-      "fortunes_url": "/fortunes",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/queries?queries=",
+      "fortune_url": "/fortunes",
       "plaintext_url": "/plaintext",
+	  "update_url": "/updates?queries=",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "MySQL",
+      "framework": "cakephp",
+      "language": "PHP",
+      "flavor": "PHP7",
+      "orm": "Full",
+      "platform": "None",
+      "webserver": "nginx",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "CakePHP 2.10 (PHP7)",
+      "notes": "",
+      "versus": "php7"
+    },
+    "php5": {
+      "setup_file": "setup_php5",
+	  "json_url": "/json",
+	  "db_url": "/db",
+	  "query_url": "/queries?queries=",
+	  "fortune_url": "/fortunes",
+	  "plaintext_url": "/plaintext",
+	  "update_url": "/updates?queries=",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Fullstack",
@@ -20,7 +45,7 @@
       "webserver": "nginx",
       "os": "Linux",
       "database_os": "Linux",
-      "display_name": "CakePHP",
+      "display_name": "CakePHP 2.10 (PHP5)",
       "notes": "",
       "versus": "php-php5"
     }

+ 1 - 1
frameworks/PHP/cakephp/composer.json

@@ -1,6 +1,6 @@
 {
     "require": {
-        "cakephp/cakephp": "2.10.3"
+        "cakephp/cakephp": "^2.10"
     },
     "config": {
         "vendor-dir": "app/Vendor"

+ 6 - 7
frameworks/PHP/cakephp/composer.lock

@@ -4,21 +4,20 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "hash": "52a4328fe44f3b0dc52d38f8341ac5b6",
-    "content-hash": "f25f483dab417e210ec599ef6033ed0e",
+    "content-hash": "0b4706d5f1d84034911f82cbe3485dc1",
     "packages": [
         {
             "name": "cakephp/cakephp",
-            "version": "2.10.3",
+            "version": "2.10.4",
             "source": {
                 "type": "git",
                 "url": "https://github.com/cakephp/cakephp.git",
-                "reference": "c3a612aa94d30a4c51653f40f55ce07177300307"
+                "reference": "549c18192643dd1160fd0d094498f24ec4d68dd9"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/cakephp/cakephp/zipball/c3a612aa94d30a4c51653f40f55ce07177300307",
-                "reference": "c3a612aa94d30a4c51653f40f55ce07177300307",
+                "url": "https://api.github.com/repos/cakephp/cakephp/zipball/549c18192643dd1160fd0d094498f24ec4d68dd9",
+                "reference": "549c18192643dd1160fd0d094498f24ec4d68dd9",
                 "shasum": ""
             },
             "require": {
@@ -48,7 +47,7 @@
             "keywords": [
                 "framework"
             ],
-            "time": "2017-09-18 02:12:29"
+            "time": "2017-10-19T01:54:49+00:00"
         }
     ],
     "packages-dev": [],

+ 0 - 9
frameworks/PHP/cakephp/deploy/cake

@@ -1,9 +0,0 @@
-<VirtualHost *:8080>
-  Alias /cake/ "/home/hyoung/FrameworkBenchmarks/cakephp/app/webroot/"
-  <Directory /home/hyoung/FrameworkBenchmarks/cakephp/app/webroot/>
-          Options Indexes FollowSymLinks MultiViews
-          #AllowOverride None
-          Order allow,deny
-          allow from all
-  </Directory>
-</VirtualHost>

+ 35 - 101
frameworks/PHP/cakephp/deploy/nginx.conf

@@ -1,67 +1,47 @@
-#user  nobody;
 worker_processes  8;
-error_log stderr error;
-
-#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;
+    worker_connections 2048;
+	multi_accept on;
+	use epoll;
 }
 
-
 http {
-    include       /usr/local/nginx/conf/mime.types;
+    include       /home/vagrant/FrameworkBenchmarks/installs/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;
+    access_log off;
+
+    sendfile on;
+    tcp_nopush on;
+    tcp_nodelay on;
+    keepalive_timeout 65;
+
+    open_file_cache max=2000 inactive=20s;
+    open_file_cache_valid 60s;
+    open_file_cache_min_uses 5;
+    open_file_cache_errors off;
+
+    #FastCGI optimizations
+    fastcgi_buffers 256 16k;
+    fastcgi_buffer_size 128k;
+    fastcgi_connect_timeout 30s;
+    fastcgi_send_timeout 60s;
+    fastcgi_read_timeout 60s;
+    fastcgi_busy_buffers_size 256k;
+    fastcgi_temp_file_write_size 256k;
+    reset_timedout_connection on;
+    server_names_hash_bucket_size 100;
+
+
+    upstream fastcgi_backend {
+        server 127.0.0.1:9001;
+    }
 
     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/hyoung/FrameworkBenchmarks/cakephp/app/webroot/;
+        root /home/vagrant/FrameworkBenchmarks/frameworks/PHP/cakephp/app/webroot/;
         index  index.php;
 
         location / {
@@ -72,56 +52,10 @@ http {
         #
         location ~ \.php$ {
             try_files $uri =404;
-            fastcgi_pass   127.0.0.1:9001;
+            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;
-            include        /usr/local/nginx/conf/fastcgi_params;
+            include        /home/vagrant/FrameworkBenchmarks/installs/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;
-    #    }
-    #}
-
-}
+}

+ 5 - 7
frameworks/PHP/cakephp/setup.sh

@@ -1,14 +1,12 @@
 #!/bin/bash
 
-fw_depends mysql php5 composer nginx
-
-php-fpm --fpm-config $FWROOT/toolset/setup/linux/languages/php/php-fpm.conf -g $TROOT/deploy/php-fpm.pid
+fw_depends mysql php7 composer nginx
 
 sed -i "s|'host' => '.*'|'host' => '${DBHOST}'|g" app/Config/database.php
 sed -i 's|REDISSERVER|'${DBHOST}'|g' app/Config/core.php
-sed -i 's|".*/FrameworkBenchmarks/cakephp|"'${TROOT}'|g' deploy/cake
-sed -i 's|Directory .*/FrameworkBenchmarks/cakephp|Directory '${TROOT}'|g' deploy/cake
-sed -i 's|root .*/FrameworkBenchmarks/cakephp|root '${TROOT}'|g' deploy/nginx.conf
-sed -i 's|/usr/local/nginx/|'${IROOT}'/nginx/|g' deploy/nginx.conf
+sed -i 's|root .*/FrameworkBenchmarks/frameworks/PHP/cakephp|root '"${TROOT}"'|g' deploy/nginx.conf
+sed -i 's|/home/vagrant/FrameworkBenchmarks/installs/nginx/|'"${IROOT}"'/nginx/|g' deploy/nginx.conf
+
+php-fpm --fpm-config $FWROOT/toolset/setup/linux/languages/php/php-fpm.conf -g $TROOT/deploy/php-fpm.pid
 
 nginx -c $TROOT/deploy/nginx.conf

+ 12 - 0
frameworks/PHP/cakephp/setup_php5.sh

@@ -0,0 +1,12 @@
+#!/bin/bash
+
+fw_depends mysql php5 composer nginx
+
+sed -i "s|'host' => '.*'|'host' => '${DBHOST}'|g" app/Config/database.php
+sed -i 's|REDISSERVER|'${DBHOST}'|g' app/Config/core.php
+sed -i 's|root .*/FrameworkBenchmarks/frameworks/PHP/cakephp|root '"${TROOT}"'|g' deploy/nginx.conf
+sed -i 's|/home/vagrant/FrameworkBenchmarks/installs/nginx/|'"${IROOT}"'/nginx/|g' deploy/nginx.conf
+
+php-fpm --fpm-config $FWROOT/toolset/setup/linux/languages/php/php-fpm.conf -g $TROOT/deploy/php-fpm.pid
+
+nginx -c $TROOT/deploy/nginx.conf