Browse Source

Fixed PHP install and silex-raw #720

Steve Smith 10 years ago
parent
commit
3fee6fecf4

+ 2 - 1
frameworks/PHP/php-silex/benchmark_config

@@ -3,8 +3,9 @@
   "tests": [{
     "default": {
       "setup_file": "setup",
+      "json_url": "/json",
       "db_url": "/db",
-      "query_url": "/db?queries=",
+      "query_url": "/queries?queries=",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Micro",

+ 5 - 3
frameworks/PHP/php-silex/setup.sh

@@ -1,13 +1,15 @@
 #!/bin/bash
 
-sed -i 's|192.168.100.102|'"${DBHOST}"'|g' web/index.php
+sed -i 's|localhost|'"${DBHOST}"'|g' web/index.php
 sed -i 's|".*\FrameworkBenchmarks/php-silex|"'"${TROOT}"'|g' deploy/php-silex
 sed -i 's|Directory .*/FrameworkBenchmarks/php-silex|Directory '"${TROOT}"'|g' deploy/php-silex
 sed -i 's|root .*/FrameworkBenchmarks/php-silex|root '"${TROOT}"'|g' deploy/nginx.conf
 sed -i 's|/usr/local/nginx/|'"${IROOT}"'/nginx/|g' deploy/nginx.conf
 
+PHP_HOME=${IROOT}/php-5.5.17
+
 export PATH="$COMPOSER_HOME:$PHP_HOME/bin:$PHP_HOME/sbin:$PATH"
 
-composer.phar install --optimize-autoloader
+${PHP_HOME}/bin/php ${IROOT}/composer.phar install --optimize-autoloader
 $PHP_FPM --fpm-config $FWROOT/config/php-fpm.conf -g $TROOT/deploy/php-fpm.pid
-$NGINX_HOME/sbin/nginx -c $TROOT/deploy/nginx.conf
+$NGINX_HOME/sbin/nginx -c $TROOT/deploy/nginx.conf

+ 5 - 3
frameworks/PHP/php-silex/setup_raw.sh

@@ -1,13 +1,15 @@
 #!/bin/bash
 
-sed -i 's|192.168.100.102|'"${DBHOST}"'|g' web/index_raw.php
+sed -i 's|localhost|'"${DBHOST}"'|g' web/index_raw.php
 sed -i 's|".*\FrameworkBenchmarks/php-silex|"'"${TROOT}"'|g' deploy/php-silex
 sed -i 's|Directory .*/FrameworkBenchmarks/php-silex|Directory '"${TROOT}"'|g' deploy/php-silex
 sed -i 's|root .*/FrameworkBenchmarks/php-silex|root '"${TROOT}"'|g' deploy/nginx_raw.conf
 sed -i 's|/usr/local/nginx/|'"${IROOT}"'/nginx/|g' deploy/nginx_raw.conf
 
+PHP_HOME=${IROOT}/php-5.5.17
+
 export PATH="$COMPOSER_HOME:$PHP_HOME/bin:$PHP_HOME/sbin:$PATH"
 
-composer.phar install --optimize-autoloader
+${PHP_HOME}/bin/php ${IROOT}/composer.phar install --optimize-autoloader
 $PHP_FPM --fpm-config $FWROOT/config/php-fpm.conf -g $TROOT/deploy/php-fpm.pid
-$NGINX_HOME/sbin/nginx -c $TROOT/deploy/nginx_raw.conf
+$NGINX_HOME/sbin/nginx -c $TROOT/deploy/nginx_raw.conf

+ 19 - 7
frameworks/PHP/php-silex/web/index.php

@@ -9,7 +9,7 @@ require_once __DIR__.'/../vendor/autoload.php';
 
 $app = new Silex\Application();
 
-$dbh = new PDO('mysql:host=192.168.100.102;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', array(
+$dbh = new PDO('mysql:host=localhost;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', array(
     PDO::ATTR_PERSISTENT => true
 ));
 
@@ -24,22 +24,34 @@ $app->get('/json', function() {
 });
 
 $app->get('/db', function(Request $request) use ($app) {
+    $world = $app['db']->fetchAssoc('SELECT * FROM World WHERE id = ?', array(mt_rand(1, 10000)));
+    $world['id'] = (int) $world['id'];
+    $world['randomNumber'] = (int) $world['randomNumber'];
+
+    return new JsonResponse($world);
+});
+
+$app->get('/queries', function(Request $request) use ($app) {
     $queries = $request->query->getInt('queries', 1);
+    if ($queries < 1) {
+        $queries = 1;
+    }
+    elseif ($queries > 500) {
+        $queries = 500;
+    }
     // possibility for micro enhancement could be the use of SplFixedArray -> http://php.net/manual/de/class.splfixedarray.php
     $worlds = array();
 
     for($i = 0; $i < $queries; ++$i) {
-        $worlds[] = $app['db']->fetchAssoc('SELECT * FROM World WHERE id = ?', array(mt_rand(1, 10000)));
-    }
-
-    if (count($worlds) == 1) {
-        $worlds = $worlds[0];
+        $world = $app['db']->fetchAssoc('SELECT * FROM World WHERE id = ?', array(mt_rand(1, 10000)));
+        $world['id'] = (int) $world['id'];
+        $world['randomNumber'] = (int) $world['randomNumber'];
+        $worlds[] = $world;
     }
 
     return new JsonResponse($worlds);
 });
 
-
 $app->run();
 
 

+ 15 - 8
frameworks/PHP/php-silex/web/index_raw.php

@@ -19,19 +19,25 @@ $app->get('/json', function() {
 
 // Test 2: Single database query
 $app->get('/db', function() {
-    $db = new mysqli('172.16.98.120', 'benchmarkdbuser', 'benchmarkdbpass', 'hello_world');
+    $db = new mysqli('localhost', 'benchmarkdbuser', 'benchmarkdbpass', 'hello_world');
     $row = mysqli_query($db, 'SELECT id, randomNumber FROM World WHERE id = '.rand(1, 10000));
+    $result = mysqli_fetch_assoc($row);
+    $result['id'] = (int) $result['id'];
+    $result['randomNumber'] = (int) $result['randomNumber'];
 
-    return new Response(json_encode(mysqli_fetch_assoc($row)), 200, array('Content-Type' => 'application/json'));
+    return new Response(json_encode($result), 200, array('Content-Type' => 'application/json'));
 });
 
 // Test 3: Multiple database queries
 $app->get('/queries', function(Request $request) {
     $queries = max(1, min($request->query->get('queries'), 500));
-    $db = new mysqli('172.16.98.120', 'benchmarkdbuser', 'benchmarkdbpass', 'hello_world');
+    $db = new mysqli('localhost', 'benchmarkdbuser', 'benchmarkdbpass', 'hello_world');
 
     for ($i=0; $i<$queries; $i++) {
-        $rows[] = mysqli_fetch_assoc(mysqli_query($db, 'SELECT id, randomNumber FROM World WHERE id = '.rand(1, 10000)));
+        $result = mysqli_fetch_assoc(mysqli_query($db, 'SELECT id, randomNumber FROM World WHERE id = '.rand(1, 10000)));
+        $result['id'] = (int) $result['id'];
+        $result['randomNumber'] = (int) $result['randomNumber'];
+        $rows[] = $result;
     }
 
     return new Response(json_encode($rows), 200, array('Content-Type' => 'application/json'));
@@ -39,12 +45,12 @@ $app->get('/queries', function(Request $request) {
 
 // Test 4: Fortunes
 $app->get('/fortunes', function() {
-    $db = new mysqli('172.16.98.120', 'benchmarkdbuser', 'benchmarkdbpass', 'hello_world');
+    $db = new mysqli('localhost', 'benchmarkdbuser', 'benchmarkdbpass', 'hello_world');
     $result = mysqli_query($db, 'SELECT * FROM Fortune');
     while ($row = mysqli_fetch_row($result)) {
         $fortunes[$row[0]] = htmlspecialchars($row[1], ENT_IGNORE);
     }
-    $fortunes[] = 'Additional fortune added at request time.';
+    $fortunes[0] = 'Additional fortune added at request time.';
 
     asort($fortunes);
 
@@ -58,13 +64,14 @@ $app->get('/fortunes', function() {
 // Test 5: Database updates
 $app->get('/updates', function(Request $request) {
     $queries = max(1, min($request->query->get('queries'), 500));
-    $db = new mysqli('172.16.98.120', 'benchmarkdbuser', 'benchmarkdbpass', 'hello_world');
+    $db = new mysqli('localhost', 'benchmarkdbuser', 'benchmarkdbpass', 'hello_world');
     for ($i=0; $i<$queries; $i++) {
         $rows[] = mysqli_fetch_assoc(mysqli_query($db, 'SELECT id, randomNumber FROM World WHERE id = '.rand(1, 10000)));
     }
 
     mysqli_autocommit($db, FALSE);
     foreach ($rows as $i => $row) {
+        $rows[$i]['id'] = (int) $rows[$i]['id'];
         $rows[$i]['randomNumber'] = rand(1, 10000);
         mysqli_query($db, "UPDATE World SET randomNumber = {$rows[$i]['randomNumber']} WHERE id = {$row['id']}");
     }
@@ -75,7 +82,7 @@ $app->get('/updates', function(Request $request) {
 
 // Test 6: Plaintext
 $app->get('/plaintext', function() {
-    return new Response('Hello World!', 200, array('Content-Type' => 'text/plain'));
+    return new Response('Hello, World!', 200, array('Content-Type' => 'text/plain'));
 });
 
 $app->run();

+ 2 - 1
toolset/setup/linux/languages/php.sh

@@ -22,7 +22,7 @@ echo "Configuring PHP quietly..."
 ./configure --prefix=$IROOT/php-${VERSION} --with-pdo-mysql \
   --with-mysql --with-mcrypt --enable-intl --enable-mbstring \
   --enable-fpm --with-fpm-user=testrunner --with-fpm-group=testrunner \
-  --with-openssl --enable-opcache --quiet
+  --with-openssl --with-mysqli --with-zlib --enable-opcache --quiet
 echo "Making PHP quietly..."
 make --quiet
 echo "Installing PHP quietly"
@@ -40,6 +40,7 @@ cp $FWROOT/config/php-fpm.conf $IROOT/php-${VERSION}/lib/php-fpm.conf
 # ========================
 echo PHP compilation finished, installing extensions
 
+$IROOT/php-${VERSION}/bin/pecl channel-update pecl.php.net
 # Apc.so
 $IROOT/php-${VERSION}/bin/pecl config-set php_ini $IROOT/php-${VERSION}/lib/php.ini
 #printf "\n" | $IROOT/php-5.5.17/bin/pecl install -f apc-beta