Browse Source

Merge branch 'benchmark/zend-framework-2' of https://github.com/Ocramius/FrameworkBenchmarks into 218

mcocciaTE 11 years ago
parent
commit
09802f3f70

+ 7 - 0
php-zend-framework/.gitignore

@@ -0,0 +1,7 @@
+/vendor
+/build
+/dist
+.DS_Store
+/tags
+.idea
+composer.lock

+ 0 - 0
php-zend-framework/__init__.py


+ 25 - 0
php-zend-framework/benchmark_config

@@ -0,0 +1,25 @@
+{
+  "framework": "ZendFramework",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/db-multi?queries=",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "MySQL",
+      "framework": "ZendFramework",
+      "language": "PHP",
+      "orm": "Full",
+      "platform": "PHP-FPM",
+      "webserver": "nginx",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "ZendFramework",
+      "notes": "",
+      "versus": "php"
+    }
+  }]
+}

+ 19 - 0
php-zend-framework/composer.json

@@ -0,0 +1,19 @@
+{
+    "name": "zendframework/skeleton-application",
+    "description": "Skeleton Application for ZF2",
+    "license": "BSD-3-Clause",
+    "keywords": [
+        "framework",
+        "zf2"
+    ],
+    "homepage": "http://framework.zend.com/",
+    "require": {
+        "php": ">=5.3.3",
+        "zendframework/zendframework": "~2.2"
+    },
+    "autoload": {
+        "psr-0": {
+            "FrameworkBenchmarks": "module/FrameworkBenchmarks/src"
+        }
+    }
+}

+ 16 - 0
php-zend-framework/config/application.config.php

@@ -0,0 +1,16 @@
+<?php
+return array(
+    'modules' => array(
+        'FrameworkBenchmarks',
+    ),
+    'module_listener_options' => array(
+        'module_paths' => array(),
+        'config_glob_paths' => array(
+            'config/autoload/{,*.}{global,local}.php',
+        ),
+        'config_cache_enabled' => true,
+        'config_cache_key'     => 'config_cache',
+        'cache_dir'            => 'data/cache',
+        'check_dependencies'   => false,
+    ),
+);

+ 0 - 0
php-zend-framework/config/autoload/.gitkeep


+ 8 - 0
php-zend-framework/config/autoload/benchmarks.local.php

@@ -0,0 +1,8 @@
+<?php
+
+return array(
+    'db' => array(
+        'driver' => 'Pdo',
+        'dsn'    => 'mysql:dbname=hello_world;host=localhost',
+    ),
+);

+ 1 - 0
php-zend-framework/data/cache/.gitignore

@@ -0,0 +1 @@
+*

+ 133 - 0
php-zend-framework/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-zend-framework/public/;
+        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_keep_conn on;
+            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;
+        }
+
+        # 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
php-zend-framework/deploy/php-zend-framework

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

+ 63 - 0
php-zend-framework/module/FrameworkBenchmarks/src/FrameworkBenchmarks/Controller/DbController.php

@@ -0,0 +1,63 @@
+<?php
+
+namespace FrameworkBenchmarks\Controller;
+
+use Zend\Mvc\Controller\AbstractActionController;
+use Zend\Stdlib\ArrayUtils;
+use Zend\View\Model\JsonModel;
+use Zend\Db\TableGateway\TableGateway;
+
+/**
+ * Controller that produces the json for the DB benchmarks of FrameworkBenchmarks
+ *
+ * @author Marco Pivetta <[email protected]>
+ * @link   http://www.techempower.com/benchmarks
+ */
+class DbController extends AbstractActionController
+{
+    /**
+     * @var \Zend\Db\TableGateway\TableGateway
+     */
+    protected $tableGateway;
+
+    /**
+     * @param TableGateway $tableGateway
+     */
+    public function __construct(TableGateway $tableGateway)
+    {
+        $this->tableGateway = $tableGateway;
+    }
+
+    /**
+     * @return \Zend\View\Model\JsonModel
+     */
+    public function dbAction()
+    {
+        $result = $this->tableGateway->select(array('id' => mt_rand(1, 10000)));
+
+        foreach ($result as $return) {
+            return new JsonModel($return);
+        }
+
+        return $this->notFoundAction();
+    }
+
+    /**
+     * @return \Zend\View\Model\JsonModel
+     */
+    public function dbMultiAction()
+    {
+        /* @var $request \Zend\Http\Request */
+        $request = $this->getRequest();
+        $queries = $request->getQuery('queries', 1);
+        $worlds  = array();
+
+        for ($i = 0; $i < $queries; $i += 1) {
+            foreach ($this->tableGateway->select(array('id' => mt_rand(1, 10000))) as $found) {
+                $worlds[] = $found;
+            }
+        }
+
+        return new JsonModel($worlds);
+    }
+}

+ 23 - 0
php-zend-framework/module/FrameworkBenchmarks/src/FrameworkBenchmarks/Controller/JsonController.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace FrameworkBenchmarks\Controller;
+
+use Zend\Mvc\Controller\AbstractActionController;
+use Zend\View\Model\JsonModel;
+
+/**
+ * Controller that produces the `hello world` json for the benchmarks of FrameworkBenchmarks
+ *
+ * @author Marco Pivetta <[email protected]>
+ * @link   http://www.techempower.com/benchmarks
+ */
+class JsonController extends AbstractActionController
+{
+    /**
+     * @return \Zend\View\Model\JsonModel
+     */
+    public function indexAction()
+    {
+        return new JsonModel(array('message' => 'Hello, World!'));
+    }
+}

+ 41 - 0
php-zend-framework/module/FrameworkBenchmarks/src/FrameworkBenchmarks/Entity/World.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace FrameworkBenchmarks\Entity;
+
+use Zend\Stdlib\ArrayObject;
+
+/**
+ * Entity that represents a single entry in the `World` collection of the benchmarks in FrameworkBenchmarks
+ *
+ * @author Marco Pivetta <[email protected]>
+ * @link   http://www.techempower.com/benchmarks
+ */
+class World extends ArrayObject
+{
+    /**
+     * @var int
+     */
+    public $id;
+
+    /**
+     * @var int
+     */
+    public $randomNumber;
+
+    /**
+     * @param array $data
+     */
+    public function exchangeArray($data)
+    {
+        $this->id           = $data['id'];
+        $this->randomNumber = $data['randomNumber'];
+    }
+
+    /**
+     * @return array
+     */
+    public function toArray()
+    {
+        return array('id' => $this->id, 'randomNumber' => $this->randomNumber);
+    }
+}

+ 78 - 0
php-zend-framework/module/FrameworkBenchmarks/src/FrameworkBenchmarks/Module.php

@@ -0,0 +1,78 @@
+<?php
+
+namespace FrameworkBenchmarks;
+
+/**
+ * Module class for the benchmarks of FrameworkBenchmarks
+ *
+ * @author Marco Pivetta <[email protected]>
+ * @link   http://www.techempower.com/benchmarks
+ */
+class Module
+{
+    /**
+     * @return array
+     */
+    public function getConfig()
+    {
+        return array(
+            'router' => array(
+                'routes' => array(
+                    'json' => array(
+                        'type' => 'Zend\Mvc\Router\Http\Literal',
+                        'options' => array(
+                            'route' => '/json',
+                            'defaults' => array(
+                                'controller' => 'FrameworkBenchmarks\Controller\JsonController',
+                                'action' => 'index',
+                            ),
+                        ),
+                    ),
+                    'db' => array(
+                        'type' => 'Zend\Mvc\Router\Http\Literal',
+                        'options' => array(
+                            'route' => '/db',
+                            'defaults' => array(
+                                'controller' => 'FrameworkBenchmarks\Controller\DbController',
+                                'action' => 'db',
+                            ),
+                        ),
+                    ),
+                    'db-multi' => array(
+                        'type' => 'Zend\Mvc\Router\Http\Literal',
+                        'options' => array(
+                            'route' => '/db-multi',
+                            'defaults' => array(
+                                'controller' => 'FrameworkBenchmarks\Controller\DbController',
+                                'action' => 'db-multi',
+                            ),
+                        ),
+                    ),
+                ),
+            ),
+            'db' => array(
+                'driver' => 'Pdo',
+                'dsn'    => 'mysql:dbname=hello_world;host=localhost',
+            ),
+            'controllers' => array(
+                'invokables' => array(
+                    'FrameworkBenchmarks\Controller\JsonController' => 'FrameworkBenchmarks\Controller\JsonController',
+                ),
+                'factories' => array(
+                    'FrameworkBenchmarks\Controller\DbController'
+                        => 'FrameworkBenchmarks\ServiceFactory\DbControllerServiceFactory'
+                ),
+            ),
+            'service_manager' => array(
+                'factories' => array(
+                    'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
+                ),
+            ),
+            'view_manager' => array(
+                'strategies' => array(
+                    'ViewJsonStrategy',
+                ),
+            ),
+        );
+    }
+}

+ 43 - 0
php-zend-framework/module/FrameworkBenchmarks/src/FrameworkBenchmarks/ServiceFactory/DbControllerServiceFactory.php

@@ -0,0 +1,43 @@
+<?php
+/**
+ * Created by JetBrains PhpStorm.
+ * User: ocramius
+ * Date: 4/28/13
+ * Time: 9:29 PM
+ * To change this template use File | Settings | File Templates.
+ */
+
+namespace FrameworkBenchmarks\ServiceFactory;
+
+use FrameworkBenchmarks\Controller\DbController;
+use FrameworkBenchmarks\Entity\World;
+use Zend\Db\ResultSet\ResultSet;
+use Zend\Db\TableGateway\TableGateway;
+use Zend\ServiceManager\FactoryInterface;
+use Zend\ServiceManager\ServiceLocatorInterface;
+
+/**
+ * Factory responsible for instantiating {@see \FrameworkBenchmarks\Controller\DbController}
+ *
+ * @author Marco Pivetta <[email protected]>
+ * @link   http://www.techempower.com/benchmarks
+ */
+class DbControllerServiceFactory implements FactoryInterface
+{
+    /**
+     * {@inheritDoc}
+     *
+     * @return \FrameworkBenchmarks\Controller\DbController
+     */
+    public function createService(ServiceLocatorInterface $serviceLocator)
+    {
+        /* @var $serviceLocator \Zend\ServiceManager\AbstractPluginManager */
+        /* @var $dbAdapter \Zend\Db\Adapter\AdapterInterface */
+        $dbAdapter          = $serviceLocator->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
+        $resultSetPrototype = new ResultSet();
+
+        $resultSetPrototype->setArrayObjectPrototype(new World());
+
+        return new DbController(new TableGateway('World', $dbAdapter, null, $resultSetPrototype));
+    }
+}

+ 16 - 0
php-zend-framework/public/.htaccess

@@ -0,0 +1,16 @@
+RewriteEngine On
+# The following rule tells Apache that if the requested filename
+# exists, simply serve it.
+RewriteCond %{REQUEST_FILENAME} -s [OR]
+RewriteCond %{REQUEST_FILENAME} -l [OR]
+RewriteCond %{REQUEST_FILENAME} -d
+RewriteRule ^.*$ - [NC,L]
+# The following rewrites all other queries to index.php. The
+# condition ensures that if you are using Apache aliases to do
+# mass virtual hosting, the base path will be prepended to
+# allow proper resolution of the index.php file; it will work
+# in non-aliased environments as well, providing a safe, one-size
+# fits all solution.
+RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
+RewriteRule ^(.*) - [E=BASE:%1]
+RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

+ 6 - 0
php-zend-framework/public/index.php

@@ -0,0 +1,6 @@
+<?php
+chdir(dirname(__DIR__));
+
+require __DIR__ . '/../vendor/autoload.php';
+
+Zend\Mvc\Application::init(require 'config/application.config.php')->run();

+ 27 - 0
php-zend-framework/setup.py

@@ -0,0 +1,27 @@
+import subprocess
+import sys
+import setup_util
+from os.path import expanduser
+
+home = expanduser("~")
+
+def start(args, logfile, errfile):
+  setup_util.replace_text("php-zend-framework/config/benchmarks.local.php", "host=localhost", "host=" + args.database_host)
+  setup_util.replace_text("php-zend-framework/deploy/nginx.conf", "root .*\/FrameworkBenchmarks", "root " + home + "/FrameworkBenchmarks")
+
+  try:
+    subprocess.check_call("composer.phar install --optimize-autoloader", shell=True, cwd="php-zend-framework", stderr=errfile, stdout=logfile)
+    subprocess.check_call("sudo chown -R www-data:www-data php-zend-framework", shell=True, stderr=errfile, stdout=logfile)
+    subprocess.check_call("sudo php-fpm --fpm-config config/php-fpm.conf -g " + home + "/FrameworkBenchmarks/php-zend-framework/deploy/php-fpm.pid", shell=True, stderr=errfile, stdout=logfile)
+    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/php-zend-framework/deploy/nginx.conf", shell=True, stderr=errfile, stdout=logfile)
+    return 0
+  except subprocess.CalledProcessError:
+    return 1
+def stop(logfile, errfile):
+  try:
+    subprocess.call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True, stderr=errfile, stdout=logfile)
+    subprocess.call("sudo kill -QUIT $( cat php-zend-framework/deploy/php-fpm.pid )", shell=True, stderr=errfile, stdout=logfile)
+    subprocess.check_call("sudo chown -R $USER:$USER php-zend-framework", shell=True, stderr=errfile, stdout=logfile)
+    return 0
+  except subprocess.CalledProcessError:
+    return 1