Browse Source

move plaintext/json from global to class scope

nareshv 11 năm trước cách đây
mục cha
commit
bce6d42ac6
3 tập tin đã thay đổi với 20 bổ sung7 xóa
  1. 4 4
      hhvm/json.php
  2. 12 0
      hhvm/once.php.inc
  3. 4 3
      hhvm/plaintext.php

+ 4 - 4
hhvm/json.php

@@ -1,7 +1,7 @@
 <?php
 //
 // 1. JSON Test
-//
-$data = json_encode(array('message' => 'Hello, World!'));
-header('Content-Type: application/json');
-echo $data;
+require_once dirname(__FILE__).'/once.php.inc';
+
+$b = new Benchmark();
+$b->bench_json();

+ 12 - 0
hhvm/once.php.inc

@@ -11,6 +11,18 @@ class Benchmark {
         ));
     }
 
+    public function bench_json()
+    {
+        header('Content-Type: application/json');
+        echo json_encode(array('message' => 'Hello, World!'));
+    }
+
+    public function bench_plaintext()
+    {
+        header('Content-Type: text/plain; charset=utf-8');
+        echo 'Hello, World!';
+    }
+
     public function bench_db()
     {
         $this->setup_db();

+ 4 - 3
hhvm/plaintext.php

@@ -1,6 +1,7 @@
 <?php
 //
 // 6. Plaintext Test
-//
-header('Content-Type: text/plain; charset=utf-8');
-echo 'Hello, World!';
+require_once dirname(__FILE__).'/once.php.inc';
+
+$b = new Benchmark();
+$b->bench_plaintext();