Completed
Push — master ( 07eea9...33c5d8 )
by Jaisen
9s
created
src/MultiCurlSequence.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -19,12 +19,12 @@  discard block
 block discarded – undo
19 19
     
20 20
     $min = PHP_INT_MAX;
21 21
     $max = 0;
22
-    foreach($this->timers as $timer)
22
+    foreach ($this->timers as $timer)
23 23
     {
24
-      if(!isset($timer['start']))
24
+      if (!isset($timer['start']))
25 25
         $timer['start'] = PHP_INT_MAX;
26 26
 
27
-      if(!isset($timer['end']))
27
+      if (!isset($timer['end']))
28 28
         $timer['end'] = 0;
29 29
 
30 30
       $min = min($timer['start'], $min);
@@ -32,14 +32,14 @@  discard block
 block discarded – undo
32 32
     }
33 33
     $this->min = $min;
34 34
     $this->max = $max;
35
-    $this->range = $max-$min;
36
-    $this->step = floatval($this->range/$this->width);
35
+    $this->range = $max - $min;
36
+    $this->step = floatval($this->range / $this->width);
37 37
   }
38 38
 
39 39
   public function renderAscii()
40 40
   {
41 41
     $tpl = '';
42
-    foreach($this->timers as $timer)
42
+    foreach ($this->timers as $timer)
43 43
      $tpl .= $this->tplAscii($timer);
44 44
     
45 45
     return $tpl;
@@ -49,16 +49,16 @@  discard block
 block discarded – undo
49 49
   {
50 50
     $lpad = $rpad = 0;
51 51
     $lspace = $chars = $rspace = '';
52
-    if($timer['start'] > $this->min)
52
+    if ($timer['start'] > $this->min)
53 53
       $lpad = intval(($timer['start'] - $this->min) / $this->step);
54
-    if($timer['end'] < $this->max)
54
+    if ($timer['end'] < $this->max)
55 55
       $rpad = intval(($this->max - $timer['end']) / $this->step);
56 56
     $mpad = $this->width - $lpad - $rpad;
57
-    if($lpad > 0)
57
+    if ($lpad > 0)
58 58
       $lspace = str_repeat(' ', $lpad);
59
-    if($mpad > 0)
59
+    if ($mpad > 0)
60 60
       $chars = str_repeat('=', $mpad);
61
-    if($rpad > 0)
61
+    if ($rpad > 0)
62 62
       $rspace = str_repeat(' ', $rpad);
63 63
     
64 64
     $tpl = <<<TPL
Please login to merge, or discard this patch.
Braces   +24 added lines, -16 removed lines patch added patch discarded remove patch
@@ -21,11 +21,13 @@  discard block
 block discarded – undo
21 21
     $max = 0;
22 22
     foreach($this->timers as $timer)
23 23
     {
24
-      if(!isset($timer['start']))
25
-        $timer['start'] = PHP_INT_MAX;
24
+      if(!isset($timer['start'])) {
25
+              $timer['start'] = PHP_INT_MAX;
26
+      }
26 27
 
27
-      if(!isset($timer['end']))
28
-        $timer['end'] = 0;
28
+      if(!isset($timer['end'])) {
29
+              $timer['end'] = 0;
30
+      }
29 31
 
30 32
       $min = min($timer['start'], $min);
31 33
       $max = max($timer['end'], $max);
@@ -39,8 +41,9 @@  discard block
 block discarded – undo
39 41
   public function renderAscii()
40 42
   {
41 43
     $tpl = '';
42
-    foreach($this->timers as $timer)
43
-     $tpl .= $this->tplAscii($timer);
44
+    foreach($this->timers as $timer) {
45
+         $tpl .= $this->tplAscii($timer);
46
+    }
44 47
     
45 48
     return $tpl;
46 49
   }
@@ -49,17 +52,22 @@  discard block
 block discarded – undo
49 52
   {
50 53
     $lpad = $rpad = 0;
51 54
     $lspace = $chars = $rspace = '';
52
-    if($timer['start'] > $this->min)
53
-      $lpad = intval(($timer['start'] - $this->min) / $this->step);
54
-    if($timer['end'] < $this->max)
55
-      $rpad = intval(($this->max - $timer['end']) / $this->step);
55
+    if($timer['start'] > $this->min) {
56
+          $lpad = intval(($timer['start'] - $this->min) / $this->step);
57
+    }
58
+    if($timer['end'] < $this->max) {
59
+          $rpad = intval(($this->max - $timer['end']) / $this->step);
60
+    }
56 61
     $mpad = $this->width - $lpad - $rpad;
57
-    if($lpad > 0)
58
-      $lspace = str_repeat(' ', $lpad);
59
-    if($mpad > 0)
60
-      $chars = str_repeat('=', $mpad);
61
-    if($rpad > 0)
62
-      $rspace = str_repeat(' ', $rpad);
62
+    if($lpad > 0) {
63
+          $lspace = str_repeat(' ', $lpad);
64
+    }
65
+    if($mpad > 0) {
66
+          $chars = str_repeat('=', $mpad);
67
+    }
68
+    if($rpad > 0) {
69
+          $rspace = str_repeat(' ', $rpad);
70
+    }
63 71
     
64 72
     $tpl = <<<TPL
65 73
 ({$timer['api']} ::  code={$timer['code']}, start={$timer['start']}, end={$timer['end']}, total={$timer['time']})
Please login to merge, or discard this patch.
src/example.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 #!/usr/bin/env php
2 2
 <?php
3
-if (php_sapi_name() !== 'cli')
3
+if (php_sapi_name() !== 'cli') {
4 4
   die();
5
+}
5 6
 
6 7
 require '../vendor/autoload.php';
7 8
 $mc = JMathai\PhpMultiCurl\MultiCurl::getInstance();
Please login to merge, or discard this patch.
src/MultiCurl.php 2 patches
Braces   +12 added lines, -10 removed lines patch added patch discarded remove patch
@@ -78,8 +78,7 @@  discard block
 block discarded – undo
78 78
       } while ($this->execStatus === CURLM_CALL_MULTI_PERFORM);
79 79
 
80 80
       return new MultiCurlManager($key);
81
-    }
82
-    else
81
+    } else
83 82
     {
84 83
       return $code;
85 84
     }
@@ -103,8 +102,9 @@  discard block
 block discarded – undo
103 102
 
104 103
         // bug in PHP 5.3.18+ where curl_multi_select can return -1
105 104
         // https://bugs.php.net/bug.php?id=63411
106
-        if($ms === -1)
107
-          usleep(100000);
105
+        if($ms === -1) {
106
+                  usleep(100000);
107
+        }
108 108
 
109 109
         // see pull request https://github.com/jmathai/php-multi-curl/pull/17
110 110
         // details here http://curl.haxx.se/libcurl/c/libcurl-errors.html
@@ -173,10 +173,11 @@  discard block
 block discarded – undo
173 173
   {
174 174
     $key = $this->getKey($done['handle']);
175 175
     $this->stopTimer($key, $done);
176
-    if($isAsynchronous)
177
-      $this->responses[$key]['data'] = curl_multi_getcontent($done['handle']);
178
-    else
179
-      $this->responses[$key]['data'] = curl_exec($done['handle']);
176
+    if($isAsynchronous) {
177
+          $this->responses[$key]['data'] = curl_multi_getcontent($done['handle']);
178
+    } else {
179
+          $this->responses[$key]['data'] = curl_exec($done['handle']);
180
+    }
180 181
 
181 182
     $this->responses[$key]['response'] = $this->responses[$key]['data'];
182 183
 
@@ -184,8 +185,9 @@  discard block
 block discarded – undo
184 185
     {
185 186
       $this->responses[$key][$name] = curl_getinfo($done['handle'], $const);
186 187
     }
187
-    if($isAsynchronous)
188
-      curl_multi_remove_handle($this->mc, $done['handle']);
188
+    if($isAsynchronous) {
189
+          curl_multi_remove_handle($this->mc, $done['handle']);
190
+    }
189 191
     curl_close($done['handle']);
190 192
   }
191 193
 
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 
30 30
   public function __construct()
31 31
   {
32
-    if(self::$singleton === 0)
32
+    if (self::$singleton === 0)
33 33
     {
34 34
       throw new MultiCurlException('This class cannot be instantiated by the new keyword.  You must instantiate it using: $obj = MultiCurl::getInstance();');
35 35
     }
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
       );
45 45
   }
46 46
   
47
-  public function reset(){
47
+  public function reset() {
48 48
       $this->requests = array();
49 49
       $this->responses = array();
50 50
       self::$timers = array();
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
   {
55 55
     $ch = curl_init($url);
56 56
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
57
-    foreach($options as $option=>$value)
57
+    foreach ($options as $option=>$value)
58 58
     {
59 59
         curl_setopt($ch, $option, $value);
60 60
     }
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 
64 64
   public function addCurl($ch)
65 65
   {
66
-    if(gettype($ch) !== 'resource')
66
+    if (gettype($ch) !== 'resource')
67 67
     {
68 68
       throw new MultiCurlInvalidParameterException('Parameter must be a valid curl handle');
69 69
     }
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
     $this->startTimer($key);
77 77
     
78 78
     // (1)
79
-    if($code === CURLM_OK || $code === CURLM_CALL_MULTI_PERFORM)
79
+    if ($code === CURLM_OK || $code === CURLM_CALL_MULTI_PERFORM)
80 80
     {
81 81
       do
82 82
       {
@@ -93,38 +93,38 @@  discard block
 block discarded – undo
93 93
 
94 94
   public function getResult($key = null)
95 95
   {
96
-    if($key != null)
96
+    if ($key != null)
97 97
     {
98
-      if(isset($this->responses[$key]['code']))
98
+      if (isset($this->responses[$key]['code']))
99 99
       {
100 100
         return $this->responses[$key];
101 101
       }
102 102
 
103 103
       $innerSleepInt = $outerSleepInt = 1;
104
-      while($this->running && ($this->execStatus == CURLM_OK || $this->execStatus == CURLM_CALL_MULTI_PERFORM))
104
+      while ($this->running && ($this->execStatus == CURLM_OK || $this->execStatus == CURLM_CALL_MULTI_PERFORM))
105 105
       {
106 106
         usleep(intval($outerSleepInt));
107
-        $outerSleepInt = intval(max(1, ($outerSleepInt*$this->sleepIncrement)));
108
-        $ms=curl_multi_select($this->mc, 0);
107
+        $outerSleepInt = intval(max(1, ($outerSleepInt * $this->sleepIncrement)));
108
+        $ms = curl_multi_select($this->mc, 0);
109 109
 
110 110
         // bug in PHP 5.3.18+ where curl_multi_select can return -1
111 111
         // https://bugs.php.net/bug.php?id=63411
112
-        if($ms === -1)
112
+        if ($ms === -1)
113 113
           usleep(100000);
114 114
 
115 115
         // see pull request https://github.com/jmathai/php-multi-curl/pull/17
116 116
         // details here http://curl.haxx.se/libcurl/c/libcurl-errors.html
117
-        if($ms >= CURLM_CALL_MULTI_PERFORM)
117
+        if ($ms >= CURLM_CALL_MULTI_PERFORM)
118 118
         {
119
-          do{
119
+          do {
120 120
             $this->execStatus = curl_multi_exec($this->mc, $this->running);
121 121
             usleep(intval($innerSleepInt));
122
-            $innerSleepInt = intval(max(1, ($innerSleepInt*$this->sleepIncrement)));
123
-          }while($this->execStatus==CURLM_CALL_MULTI_PERFORM);
122
+            $innerSleepInt = intval(max(1, ($innerSleepInt * $this->sleepIncrement)));
123
+          } while ($this->execStatus == CURLM_CALL_MULTI_PERFORM);
124 124
           $innerSleepInt = 1;
125 125
         }
126 126
         $this->storeResponses();
127
-        if(isset($this->responses[$key]['data']))
127
+        if (isset($this->responses[$key]['data']))
128 128
         {
129 129
           return $this->responses[$key];
130 130
         }
@@ -157,11 +157,11 @@  discard block
 block discarded – undo
157 157
   private function headerCallback($ch, $header)
158 158
   {
159 159
     $_header = trim($header);
160
-    $colonPos= strpos($_header, ':');
161
-    if($colonPos > 0)
160
+    $colonPos = strpos($_header, ':');
161
+    if ($colonPos > 0)
162 162
     {
163 163
       $key = substr($_header, 0, $colonPos);
164
-      $val = preg_replace('/^\W+/','',substr($_header, $colonPos));
164
+      $val = preg_replace('/^\W+/', '', substr($_header, $colonPos));
165 165
       $this->responses[$this->getKey($ch)]['headers'][$key] = $val;
166 166
     }
167 167
     return strlen($header);
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 
170 170
   private function storeResponses()
171 171
   {
172
-    while($done = curl_multi_info_read($this->mc))
172
+    while ($done = curl_multi_info_read($this->mc))
173 173
     {
174 174
       $this->storeResponse($done);
175 175
     }
@@ -179,18 +179,18 @@  discard block
 block discarded – undo
179 179
   {
180 180
     $key = $this->getKey($done['handle']);
181 181
     $this->stopTimer($key, $done);
182
-    if($isAsynchronous)
182
+    if ($isAsynchronous)
183 183
       $this->responses[$key]['data'] = curl_multi_getcontent($done['handle']);
184 184
     else
185 185
       $this->responses[$key]['data'] = curl_exec($done['handle']);
186 186
 
187 187
     $this->responses[$key]['response'] = $this->responses[$key]['data'];
188 188
 
189
-    foreach($this->properties as $name => $const)
189
+    foreach ($this->properties as $name => $const)
190 190
     {
191 191
       $this->responses[$key][$name] = curl_getinfo($done['handle'], $const);
192 192
     }
193
-    if($isAsynchronous)
193
+    if ($isAsynchronous)
194 194
       curl_multi_remove_handle($this->mc, $done['handle']);
195 195
     curl_close($done['handle']);
196 196
   }
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 
211 211
   public static function getInstance()
212 212
   {
213
-    if(self::$inst == null)
213
+    if (self::$inst == null)
214 214
     {
215 215
       self::$singleton = 1;
216 216
       self::$inst = new MultiCurl();
Please login to merge, or discard this patch.