@@ -69,7 +69,7 @@ |
||
| 69 | 69 | /** |
| 70 | 70 | * Let's check the password |
| 71 | 71 | * @param string Password |
| 72 | - * @return boolean |
|
| 72 | + * @return boolean|null |
|
| 73 | 73 | */ |
| 74 | 74 | private function checkPassword($pass = '') { |
| 75 | 75 | if ($pass != $this->pool->config->passphrase->value) { |
@@ -140,8 +140,7 @@ |
||
| 140 | 140 | |
| 141 | 141 | if (in_array($cmd, array('quit', 'exit'))) { |
| 142 | 142 | $this->disconnect(); |
| 143 | - } |
|
| 144 | - elseif (!$this->auth) { |
|
| 143 | + } elseif (!$this->auth) { |
|
| 145 | 144 | $this->checkPassword($e[0]); |
| 146 | 145 | } else { |
| 147 | 146 | $this->processCommand($cmd, $arg); |
@@ -152,6 +152,11 @@ |
||
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | 154 | } |
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @param string $hostname |
|
| 158 | + * @param Closure $cb |
|
| 159 | + */ |
|
| 155 | 160 | public function get($hostname, $cb, $noncache = false) { |
| 156 | 161 | if (!$this->preloading->hasCompleted()) { |
| 157 | 162 | $pool = $this; |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | class DNSClient extends NetworkClient { |
| 9 | 9 | public static $type = array( |
| 10 | - 1 => 'A', 2 => 'NS', 3 => 'MD', 4 => 'MF', 5 => 'CNAME', |
|
| 10 | + 1 => 'A', 2 => 'NS', 3 => 'MD', 4 => 'MF', 5 => 'CNAME', |
|
| 11 | 11 | 6 => 'SOA', 7 => 'MB', 8 => 'MG', 9 => 'MR', 10 => 'RR', |
| 12 | 12 | 11 => 'WKS', 12 => 'PTR', 13 => 'HINFO', 14 => 'MINFO', |
| 13 | 13 | 15 => 'MX', 16 => 'TXT', 17 => 'RP', 18 => 'AFSDB', |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | $this->preloading = new ComplexJob; |
| 66 | 66 | } |
| 67 | 67 | $job = $this->preloading; |
| 68 | - $job->addJob('resolvfile', function ($jobname, $job) use ($pool) { |
|
| 68 | + $job->addJob('resolvfile', function($jobname, $job) use ($pool) { |
|
| 69 | 69 | FS::readfile($pool->config->resolvfile->value, function($file, $data) use ($pool, $job, $jobname) { |
| 70 | 70 | if ($file) { |
| 71 | 71 | preg_match_all('~nameserver ([^\r\n;]+)~', $data, $m); |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | $job->setResult($jobname); |
| 78 | 78 | }); |
| 79 | 79 | }); |
| 80 | - $job->addJob('hostsfile', function ($jobname, $job) use ($pool) { |
|
| 80 | + $job->addJob('hostsfile', function($jobname, $job) use ($pool) { |
|
| 81 | 81 | FS::readfile($pool->config->hostsfile->value, function($file, $data) use ($pool, $job, $jobname) { |
| 82 | 82 | if ($file) { |
| 83 | 83 | preg_match_all('~^(\S+)\s+([^\r\n]+)\s*~m', $data, $m, PREG_SET_ORDER); |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | public function resolve($hostname, $cb, $noncache = false) { |
| 101 | 101 | if (!$this->preloading->hasCompleted()) { |
| 102 | 102 | $pool = $this; |
| 103 | - $this->preloading->addListener(function ($job) use ($hostname, $cb, $noncache, $pool) { |
|
| 103 | + $this->preloading->addListener(function($job) use ($hostname, $cb, $noncache, $pool) { |
|
| 104 | 104 | $pool->resolve($hostname, $cb, $noncache); |
| 105 | 105 | }); |
| 106 | 106 | return; |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | $item->addListener($cb); |
| 124 | 124 | } |
| 125 | 125 | $pool = $this; |
| 126 | - $this->get($hostname, function ($response) use ($cb, $noncache, $hostname, $pool) { |
|
| 126 | + $this->get($hostname, function($response) use ($cb, $noncache, $hostname, $pool) { |
|
| 127 | 127 | if (!isset($response['A'])) { |
| 128 | 128 | if ($noncache) { |
| 129 | 129 | call_user_func($cb, false); |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | public function get($hostname, $cb, $noncache = false) { |
| 156 | 156 | if (!$this->preloading->hasCompleted()) { |
| 157 | 157 | $pool = $this; |
| 158 | - $this->preloading->addListener(function ($job) use ($hostname, $cb, $noncache, $pool) { |
|
| 158 | + $this->preloading->addListener(function($job) use ($hostname, $cb, $noncache, $pool) { |
|
| 159 | 159 | $pool->get($hostname, $cb, $noncache); |
| 160 | 160 | }); |
| 161 | 161 | return; |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | call_user_func($cb, false); |
| 179 | 179 | return; |
| 180 | 180 | } |
| 181 | - $q = Binary::labels($hostname) . // domain |
|
| 181 | + $q = Binary::labels($hostname) . // domain |
|
| 182 | 182 | Binary::word($qtypeInt) . |
| 183 | 183 | Binary::word($qclassInt); |
| 184 | 184 | $QD[] = $q; |
@@ -294,11 +294,9 @@ |
||
| 294 | 294 | } else { |
| 295 | 295 | $record['ip'] = inet_ntop($data); |
| 296 | 296 | } |
| 297 | - } |
|
| 298 | - elseif ($type === 'NS') { |
|
| 297 | + } elseif ($type === 'NS') { |
|
| 299 | 298 | $record['ns'] = Binary::parseLabels($data); |
| 300 | - } |
|
| 301 | - elseif ($type === 'CNAME') { |
|
| 299 | + } elseif ($type === 'CNAME') { |
|
| 302 | 300 | $record['cname'] = Binary::parseLabels($data, $orig); |
| 303 | 301 | } |
| 304 | 302 | |
@@ -114,6 +114,9 @@ |
||
| 114 | 114 | "\xc5\xb8" => "\x9f" |
| 115 | 115 | ); |
| 116 | 116 | |
| 117 | + /** |
|
| 118 | + * @param string $text |
|
| 119 | + */ |
|
| 117 | 120 | static function toUTF8($text){
|
| 118 | 121 | /** |
| 119 | 122 | * Function Encoding::toUTF8 |
@@ -5,114 +5,114 @@ discard block |
||
| 5 | 5 | * @version 1.1 |
| 6 | 6 | * @link http://www.framework2.com.ar/dzone/forceUTF8-es/ |
| 7 | 7 | * @example http://www.framework2.com.ar/dzone/forceUTF8-es/ |
| 8 | - */ |
|
| 8 | + */ |
|
| 9 | 9 | |
| 10 | 10 | class Encoding {
|
| 11 | 11 | |
| 12 | 12 | protected static $win1252ToUtf8 = array( |
| 13 | - 128 => "\xe2\x82\xac", |
|
| 13 | + 128 => "\xe2\x82\xac", |
|
| 14 | 14 | |
| 15 | - 130 => "\xe2\x80\x9a", |
|
| 16 | - 131 => "\xc6\x92", |
|
| 17 | - 132 => "\xe2\x80\x9e", |
|
| 18 | - 133 => "\xe2\x80\xa6", |
|
| 19 | - 134 => "\xe2\x80\xa0", |
|
| 20 | - 135 => "\xe2\x80\xa1", |
|
| 21 | - 136 => "\xcb\x86", |
|
| 22 | - 137 => "\xe2\x80\xb0", |
|
| 23 | - 138 => "\xc5\xa0", |
|
| 24 | - 139 => "\xe2\x80\xb9", |
|
| 25 | - 140 => "\xc5\x92", |
|
| 15 | + 130 => "\xe2\x80\x9a", |
|
| 16 | + 131 => "\xc6\x92", |
|
| 17 | + 132 => "\xe2\x80\x9e", |
|
| 18 | + 133 => "\xe2\x80\xa6", |
|
| 19 | + 134 => "\xe2\x80\xa0", |
|
| 20 | + 135 => "\xe2\x80\xa1", |
|
| 21 | + 136 => "\xcb\x86", |
|
| 22 | + 137 => "\xe2\x80\xb0", |
|
| 23 | + 138 => "\xc5\xa0", |
|
| 24 | + 139 => "\xe2\x80\xb9", |
|
| 25 | + 140 => "\xc5\x92", |
|
| 26 | 26 | |
| 27 | - 142 => "\xc5\xbd", |
|
| 27 | + 142 => "\xc5\xbd", |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | - 145 => "\xe2\x80\x98", |
|
| 31 | - 146 => "\xe2\x80\x99", |
|
| 32 | - 147 => "\xe2\x80\x9c", |
|
| 33 | - 148 => "\xe2\x80\x9d", |
|
| 34 | - 149 => "\xe2\x80\xa2", |
|
| 35 | - 150 => "\xe2\x80\x93", |
|
| 36 | - 151 => "\xe2\x80\x94", |
|
| 37 | - 152 => "\xcb\x9c", |
|
| 38 | - 153 => "\xe2\x84\xa2", |
|
| 39 | - 154 => "\xc5\xa1", |
|
| 40 | - 155 => "\xe2\x80\xba", |
|
| 41 | - 156 => "\xc5\x93", |
|
| 30 | + 145 => "\xe2\x80\x98", |
|
| 31 | + 146 => "\xe2\x80\x99", |
|
| 32 | + 147 => "\xe2\x80\x9c", |
|
| 33 | + 148 => "\xe2\x80\x9d", |
|
| 34 | + 149 => "\xe2\x80\xa2", |
|
| 35 | + 150 => "\xe2\x80\x93", |
|
| 36 | + 151 => "\xe2\x80\x94", |
|
| 37 | + 152 => "\xcb\x9c", |
|
| 38 | + 153 => "\xe2\x84\xa2", |
|
| 39 | + 154 => "\xc5\xa1", |
|
| 40 | + 155 => "\xe2\x80\xba", |
|
| 41 | + 156 => "\xc5\x93", |
|
| 42 | 42 | |
| 43 | - 158 => "\xc5\xbe", |
|
| 44 | - 159 => "\xc5\xb8" |
|
| 43 | + 158 => "\xc5\xbe", |
|
| 44 | + 159 => "\xc5\xb8" |
|
| 45 | 45 | ); |
| 46 | 46 | |
| 47 | - protected static $brokenUtf8ToUtf8 = array( |
|
| 48 | - "\xc2\x80" => "\xe2\x82\xac", |
|
| 47 | + protected static $brokenUtf8ToUtf8 = array( |
|
| 48 | + "\xc2\x80" => "\xe2\x82\xac", |
|
| 49 | 49 | |
| 50 | - "\xc2\x82" => "\xe2\x80\x9a", |
|
| 51 | - "\xc2\x83" => "\xc6\x92", |
|
| 52 | - "\xc2\x84" => "\xe2\x80\x9e", |
|
| 53 | - "\xc2\x85" => "\xe2\x80\xa6", |
|
| 54 | - "\xc2\x86" => "\xe2\x80\xa0", |
|
| 55 | - "\xc2\x87" => "\xe2\x80\xa1", |
|
| 56 | - "\xc2\x88" => "\xcb\x86", |
|
| 57 | - "\xc2\x89" => "\xe2\x80\xb0", |
|
| 58 | - "\xc2\x8a" => "\xc5\xa0", |
|
| 59 | - "\xc2\x8b" => "\xe2\x80\xb9", |
|
| 60 | - "\xc2\x8c" => "\xc5\x92", |
|
| 50 | + "\xc2\x82" => "\xe2\x80\x9a", |
|
| 51 | + "\xc2\x83" => "\xc6\x92", |
|
| 52 | + "\xc2\x84" => "\xe2\x80\x9e", |
|
| 53 | + "\xc2\x85" => "\xe2\x80\xa6", |
|
| 54 | + "\xc2\x86" => "\xe2\x80\xa0", |
|
| 55 | + "\xc2\x87" => "\xe2\x80\xa1", |
|
| 56 | + "\xc2\x88" => "\xcb\x86", |
|
| 57 | + "\xc2\x89" => "\xe2\x80\xb0", |
|
| 58 | + "\xc2\x8a" => "\xc5\xa0", |
|
| 59 | + "\xc2\x8b" => "\xe2\x80\xb9", |
|
| 60 | + "\xc2\x8c" => "\xc5\x92", |
|
| 61 | 61 | |
| 62 | - "\xc2\x8e" => "\xc5\xbd", |
|
| 62 | + "\xc2\x8e" => "\xc5\xbd", |
|
| 63 | 63 | |
| 64 | 64 | |
| 65 | - "\xc2\x91" => "\xe2\x80\x98", |
|
| 66 | - "\xc2\x92" => "\xe2\x80\x99", |
|
| 67 | - "\xc2\x93" => "\xe2\x80\x9c", |
|
| 68 | - "\xc2\x94" => "\xe2\x80\x9d", |
|
| 69 | - "\xc2\x95" => "\xe2\x80\xa2", |
|
| 70 | - "\xc2\x96" => "\xe2\x80\x93", |
|
| 71 | - "\xc2\x97" => "\xe2\x80\x94", |
|
| 72 | - "\xc2\x98" => "\xcb\x9c", |
|
| 73 | - "\xc2\x99" => "\xe2\x84\xa2", |
|
| 74 | - "\xc2\x9a" => "\xc5\xa1", |
|
| 75 | - "\xc2\x9b" => "\xe2\x80\xba", |
|
| 76 | - "\xc2\x9c" => "\xc5\x93", |
|
| 65 | + "\xc2\x91" => "\xe2\x80\x98", |
|
| 66 | + "\xc2\x92" => "\xe2\x80\x99", |
|
| 67 | + "\xc2\x93" => "\xe2\x80\x9c", |
|
| 68 | + "\xc2\x94" => "\xe2\x80\x9d", |
|
| 69 | + "\xc2\x95" => "\xe2\x80\xa2", |
|
| 70 | + "\xc2\x96" => "\xe2\x80\x93", |
|
| 71 | + "\xc2\x97" => "\xe2\x80\x94", |
|
| 72 | + "\xc2\x98" => "\xcb\x9c", |
|
| 73 | + "\xc2\x99" => "\xe2\x84\xa2", |
|
| 74 | + "\xc2\x9a" => "\xc5\xa1", |
|
| 75 | + "\xc2\x9b" => "\xe2\x80\xba", |
|
| 76 | + "\xc2\x9c" => "\xc5\x93", |
|
| 77 | 77 | |
| 78 | - "\xc2\x9e" => "\xc5\xbe", |
|
| 79 | - "\xc2\x9f" => "\xc5\xb8" |
|
| 78 | + "\xc2\x9e" => "\xc5\xbe", |
|
| 79 | + "\xc2\x9f" => "\xc5\xb8" |
|
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | 82 | protected static $utf8ToWin1252 = array( |
| 83 | - "\xe2\x82\xac" => "\x80", |
|
| 83 | + "\xe2\x82\xac" => "\x80", |
|
| 84 | 84 | |
| 85 | - "\xe2\x80\x9a" => "\x82", |
|
| 86 | - "\xc6\x92" => "\x83", |
|
| 87 | - "\xe2\x80\x9e" => "\x84", |
|
| 88 | - "\xe2\x80\xa6" => "\x85", |
|
| 89 | - "\xe2\x80\xa0" => "\x86", |
|
| 90 | - "\xe2\x80\xa1" => "\x87", |
|
| 91 | - "\xcb\x86" => "\x88", |
|
| 92 | - "\xe2\x80\xb0" => "\x89", |
|
| 93 | - "\xc5\xa0" => "\x8a", |
|
| 94 | - "\xe2\x80\xb9" => "\x8b", |
|
| 95 | - "\xc5\x92" => "\x8c", |
|
| 85 | + "\xe2\x80\x9a" => "\x82", |
|
| 86 | + "\xc6\x92" => "\x83", |
|
| 87 | + "\xe2\x80\x9e" => "\x84", |
|
| 88 | + "\xe2\x80\xa6" => "\x85", |
|
| 89 | + "\xe2\x80\xa0" => "\x86", |
|
| 90 | + "\xe2\x80\xa1" => "\x87", |
|
| 91 | + "\xcb\x86" => "\x88", |
|
| 92 | + "\xe2\x80\xb0" => "\x89", |
|
| 93 | + "\xc5\xa0" => "\x8a", |
|
| 94 | + "\xe2\x80\xb9" => "\x8b", |
|
| 95 | + "\xc5\x92" => "\x8c", |
|
| 96 | 96 | |
| 97 | - "\xc5\xbd" => "\x8e", |
|
| 97 | + "\xc5\xbd" => "\x8e", |
|
| 98 | 98 | |
| 99 | 99 | |
| 100 | - "\xe2\x80\x98" => "\x91", |
|
| 101 | - "\xe2\x80\x99" => "\x92", |
|
| 102 | - "\xe2\x80\x9c" => "\x93", |
|
| 103 | - "\xe2\x80\x9d" => "\x94", |
|
| 104 | - "\xe2\x80\xa2" => "\x95", |
|
| 105 | - "\xe2\x80\x93" => "\x96", |
|
| 106 | - "\xe2\x80\x94" => "\x97", |
|
| 107 | - "\xcb\x9c" => "\x98", |
|
| 108 | - "\xe2\x84\xa2" => "\x99", |
|
| 109 | - "\xc5\xa1" => "\x9a", |
|
| 110 | - "\xe2\x80\xba" => "\x9b", |
|
| 111 | - "\xc5\x93" => "\x9c", |
|
| 100 | + "\xe2\x80\x98" => "\x91", |
|
| 101 | + "\xe2\x80\x99" => "\x92", |
|
| 102 | + "\xe2\x80\x9c" => "\x93", |
|
| 103 | + "\xe2\x80\x9d" => "\x94", |
|
| 104 | + "\xe2\x80\xa2" => "\x95", |
|
| 105 | + "\xe2\x80\x93" => "\x96", |
|
| 106 | + "\xe2\x80\x94" => "\x97", |
|
| 107 | + "\xcb\x9c" => "\x98", |
|
| 108 | + "\xe2\x84\xa2" => "\x99", |
|
| 109 | + "\xc5\xa1" => "\x9a", |
|
| 110 | + "\xe2\x80\xba" => "\x9b", |
|
| 111 | + "\xc5\x93" => "\x9c", |
|
| 112 | 112 | |
| 113 | - "\xc5\xbe" => "\x9e", |
|
| 114 | - "\xc5\xb8" => "\x9f" |
|
| 115 | - ); |
|
| 113 | + "\xc5\xbe" => "\x9e", |
|
| 114 | + "\xc5\xb8" => "\x9f" |
|
| 115 | + ); |
|
| 116 | 116 | |
| 117 | 117 | static function toUTF8($text){
|
| 118 | 118 | /** |
@@ -140,123 +140,123 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | */ |
| 142 | 142 | |
| 143 | - if(is_array($text)) |
|
| 144 | - {
|
|
| 145 | - foreach($text as $k => $v) |
|
| 146 | - {
|
|
| 147 | - $text[$k] = self::toUTF8($v); |
|
| 148 | - } |
|
| 149 | - return $text; |
|
| 150 | - } elseif(is_string($text)) {
|
|
| 143 | + if(is_array($text)) |
|
| 144 | + {
|
|
| 145 | + foreach($text as $k => $v) |
|
| 146 | + {
|
|
| 147 | + $text[$k] = self::toUTF8($v); |
|
| 148 | + } |
|
| 149 | + return $text; |
|
| 150 | + } elseif(is_string($text)) {
|
|
| 151 | 151 | |
| 152 | - $max = strlen($text); |
|
| 153 | - $buf = ""; |
|
| 154 | - for($i = 0; $i < $max; $i++){
|
|
| 155 | - $c1 = $text{$i};
|
|
| 156 | - if($c1>="\xc0"){ //Should be converted to UTF8, if it's not UTF8 already
|
|
| 157 | - $c2 = $i+1 >= $max? "\x00" : $text{$i+1};
|
|
| 158 | - $c3 = $i+2 >= $max? "\x00" : $text{$i+2};
|
|
| 159 | - $c4 = $i+3 >= $max? "\x00" : $text{$i+3};
|
|
| 160 | - if($c1 >= "\xc0" & $c1 <= "\xdf"){ //looks like 2 bytes UTF8
|
|
| 161 | - if($c2 >= "\x80" && $c2 <= "\xbf"){ //yeah, almost sure it's UTF8 already
|
|
| 162 | - $buf .= $c1 . $c2; |
|
| 163 | - $i++; |
|
| 164 | - } else { //not valid UTF8. Convert it.
|
|
| 165 | - $cc1 = (chr(ord($c1) / 64) | "\xc0"); |
|
| 166 | - $cc2 = ($c1 & "\x3f") | "\x80"; |
|
| 167 | - $buf .= $cc1 . $cc2; |
|
| 168 | - } |
|
| 169 | - } elseif($c1 >= "\xe0" & $c1 <= "\xef"){ //looks like 3 bytes UTF8
|
|
| 170 | - if($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf"){ //yeah, almost sure it's UTF8 already
|
|
| 171 | - $buf .= $c1 . $c2 . $c3; |
|
| 172 | - $i = $i + 2; |
|
| 173 | - } else { //not valid UTF8. Convert it.
|
|
| 174 | - $cc1 = (chr(ord($c1) / 64) | "\xc0"); |
|
| 175 | - $cc2 = ($c1 & "\x3f") | "\x80"; |
|
| 176 | - $buf .= $cc1 . $cc2; |
|
| 177 | - } |
|
| 178 | - } elseif($c1 >= "\xf0" & $c1 <= "\xf7"){ //looks like 4 bytes UTF8
|
|
| 179 | - if($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf" && $c4 >= "\x80" && $c4 <= "\xbf"){ //yeah, almost sure it's UTF8 already
|
|
| 180 | - $buf .= $c1 . $c2 . $c3; |
|
| 181 | - $i = $i + 2; |
|
| 182 | - } else { //not valid UTF8. Convert it.
|
|
| 183 | - $cc1 = (chr(ord($c1) / 64) | "\xc0"); |
|
| 184 | - $cc2 = ($c1 & "\x3f") | "\x80"; |
|
| 185 | - $buf .= $cc1 . $cc2; |
|
| 186 | - } |
|
| 187 | - } else { //doesn't look like UTF8, but should be converted
|
|
| 188 | - $cc1 = (chr(ord($c1) / 64) | "\xc0"); |
|
| 189 | - $cc2 = (($c1 & "\x3f") | "\x80"); |
|
| 190 | - $buf .= $cc1 . $cc2; |
|
| 191 | - } |
|
| 192 | - } elseif(($c1 & "\xc0") == "\x80"){ // needs conversion
|
|
| 193 | - if(isset(self::$win1252ToUtf8[ord($c1)])) { //found in Windows-1252 special cases
|
|
| 194 | - $buf .= self::$win1252ToUtf8[ord($c1)]; |
|
| 195 | - } else {
|
|
| 196 | - $cc1 = (chr(ord($c1) / 64) | "\xc0"); |
|
| 197 | - $cc2 = (($c1 & "\x3f") | "\x80"); |
|
| 198 | - $buf .= $cc1 . $cc2; |
|
| 199 | - } |
|
| 200 | - } else { // it doesn't need convesion
|
|
| 201 | - $buf .= $c1; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - return $buf; |
|
| 205 | - } else {
|
|
| 206 | - return $text; |
|
| 207 | - } |
|
| 152 | + $max = strlen($text); |
|
| 153 | + $buf = ""; |
|
| 154 | + for($i = 0; $i < $max; $i++){
|
|
| 155 | + $c1 = $text{$i};
|
|
| 156 | + if($c1>="\xc0"){ //Should be converted to UTF8, if it's not UTF8 already
|
|
| 157 | + $c2 = $i+1 >= $max? "\x00" : $text{$i+1};
|
|
| 158 | + $c3 = $i+2 >= $max? "\x00" : $text{$i+2};
|
|
| 159 | + $c4 = $i+3 >= $max? "\x00" : $text{$i+3};
|
|
| 160 | + if($c1 >= "\xc0" & $c1 <= "\xdf"){ //looks like 2 bytes UTF8
|
|
| 161 | + if($c2 >= "\x80" && $c2 <= "\xbf"){ //yeah, almost sure it's UTF8 already
|
|
| 162 | + $buf .= $c1 . $c2; |
|
| 163 | + $i++; |
|
| 164 | + } else { //not valid UTF8. Convert it.
|
|
| 165 | + $cc1 = (chr(ord($c1) / 64) | "\xc0"); |
|
| 166 | + $cc2 = ($c1 & "\x3f") | "\x80"; |
|
| 167 | + $buf .= $cc1 . $cc2; |
|
| 168 | + } |
|
| 169 | + } elseif($c1 >= "\xe0" & $c1 <= "\xef"){ //looks like 3 bytes UTF8
|
|
| 170 | + if($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf"){ //yeah, almost sure it's UTF8 already
|
|
| 171 | + $buf .= $c1 . $c2 . $c3; |
|
| 172 | + $i = $i + 2; |
|
| 173 | + } else { //not valid UTF8. Convert it.
|
|
| 174 | + $cc1 = (chr(ord($c1) / 64) | "\xc0"); |
|
| 175 | + $cc2 = ($c1 & "\x3f") | "\x80"; |
|
| 176 | + $buf .= $cc1 . $cc2; |
|
| 177 | + } |
|
| 178 | + } elseif($c1 >= "\xf0" & $c1 <= "\xf7"){ //looks like 4 bytes UTF8
|
|
| 179 | + if($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf" && $c4 >= "\x80" && $c4 <= "\xbf"){ //yeah, almost sure it's UTF8 already
|
|
| 180 | + $buf .= $c1 . $c2 . $c3; |
|
| 181 | + $i = $i + 2; |
|
| 182 | + } else { //not valid UTF8. Convert it.
|
|
| 183 | + $cc1 = (chr(ord($c1) / 64) | "\xc0"); |
|
| 184 | + $cc2 = ($c1 & "\x3f") | "\x80"; |
|
| 185 | + $buf .= $cc1 . $cc2; |
|
| 186 | + } |
|
| 187 | + } else { //doesn't look like UTF8, but should be converted
|
|
| 188 | + $cc1 = (chr(ord($c1) / 64) | "\xc0"); |
|
| 189 | + $cc2 = (($c1 & "\x3f") | "\x80"); |
|
| 190 | + $buf .= $cc1 . $cc2; |
|
| 191 | + } |
|
| 192 | + } elseif(($c1 & "\xc0") == "\x80"){ // needs conversion
|
|
| 193 | + if(isset(self::$win1252ToUtf8[ord($c1)])) { //found in Windows-1252 special cases
|
|
| 194 | + $buf .= self::$win1252ToUtf8[ord($c1)]; |
|
| 195 | + } else {
|
|
| 196 | + $cc1 = (chr(ord($c1) / 64) | "\xc0"); |
|
| 197 | + $cc2 = (($c1 & "\x3f") | "\x80"); |
|
| 198 | + $buf .= $cc1 . $cc2; |
|
| 199 | + } |
|
| 200 | + } else { // it doesn't need convesion
|
|
| 201 | + $buf .= $c1; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + return $buf; |
|
| 205 | + } else {
|
|
| 206 | + return $text; |
|
| 207 | + } |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | static function toWin1252($text) {
|
| 211 | - if(is_array($text)) {
|
|
| 212 | - foreach($text as $k => $v) {
|
|
| 213 | - $text[$k] = self::toWin1252($v); |
|
| 214 | - } |
|
| 215 | - return $text; |
|
| 216 | - } elseif(is_string($text)) {
|
|
| 217 | - return utf8_decode(str_replace(array_keys(self::$utf8ToWin1252), array_values(self::$utf8ToWin1252), self::toUTF8($text))); |
|
| 218 | - } else {
|
|
| 219 | - return $text; |
|
| 220 | - } |
|
| 211 | + if(is_array($text)) {
|
|
| 212 | + foreach($text as $k => $v) {
|
|
| 213 | + $text[$k] = self::toWin1252($v); |
|
| 214 | + } |
|
| 215 | + return $text; |
|
| 216 | + } elseif(is_string($text)) {
|
|
| 217 | + return utf8_decode(str_replace(array_keys(self::$utf8ToWin1252), array_values(self::$utf8ToWin1252), self::toUTF8($text))); |
|
| 218 | + } else {
|
|
| 219 | + return $text; |
|
| 220 | + } |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | static function toISO8859($text) {
|
| 224 | - return self::toWin1252($text); |
|
| 224 | + return self::toWin1252($text); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | static function toLatin1($text) {
|
| 228 | - return self::toWin1252($text); |
|
| 228 | + return self::toWin1252($text); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | static function fixUTF8($text){
|
| 232 | - if(is_array($text)) {
|
|
| 233 | - foreach($text as $k => $v) {
|
|
| 234 | - $text[$k] = self::fixUTF8($v); |
|
| 235 | - } |
|
| 236 | - return $text; |
|
| 237 | - } |
|
| 232 | + if(is_array($text)) {
|
|
| 233 | + foreach($text as $k => $v) {
|
|
| 234 | + $text[$k] = self::fixUTF8($v); |
|
| 235 | + } |
|
| 236 | + return $text; |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - $last = ""; |
|
| 240 | - while($last <> $text){
|
|
| 241 | - $last = $text; |
|
| 242 | - $text = self::toUTF8(utf8_decode(str_replace(array_keys(self::$utf8ToWin1252), array_values(self::$utf8ToWin1252), $text))); |
|
| 243 | - } |
|
| 244 | - $text = self::toUTF8(utf8_decode(str_replace(array_keys(self::$utf8ToWin1252), array_values(self::$utf8ToWin1252), $text))); |
|
| 245 | - return $text; |
|
| 239 | + $last = ""; |
|
| 240 | + while($last <> $text){
|
|
| 241 | + $last = $text; |
|
| 242 | + $text = self::toUTF8(utf8_decode(str_replace(array_keys(self::$utf8ToWin1252), array_values(self::$utf8ToWin1252), $text))); |
|
| 243 | + } |
|
| 244 | + $text = self::toUTF8(utf8_decode(str_replace(array_keys(self::$utf8ToWin1252), array_values(self::$utf8ToWin1252), $text))); |
|
| 245 | + return $text; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | static function UTF8FixWin1252Chars($text){
|
| 249 | - // If you received an UTF-8 string that was converted from Windows-1252 as it was ISO8859-1 |
|
| 250 | - // (ignoring Windows-1252 chars from 80 to 9F) use this function to fix it. |
|
| 251 | - // See: http://en.wikipedia.org/wiki/Windows-1252 |
|
| 249 | + // If you received an UTF-8 string that was converted from Windows-1252 as it was ISO8859-1 |
|
| 250 | + // (ignoring Windows-1252 chars from 80 to 9F) use this function to fix it. |
|
| 251 | + // See: http://en.wikipedia.org/wiki/Windows-1252 |
|
| 252 | 252 | |
| 253 | - return str_replace(array_keys(self::$brokenUtf8ToUtf8), array_values(self::$brokenUtf8ToUtf8), $text); |
|
| 253 | + return str_replace(array_keys(self::$brokenUtf8ToUtf8), array_values(self::$brokenUtf8ToUtf8), $text); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | static function removeBOM($str=""){
|
| 257 | - if(substr($str, 0,3) == pack("CCC",0xef,0xbb,0xbf)) {
|
|
| 258 | - $str=substr($str, 3); |
|
| 259 | - } |
|
| 260 | - return $str; |
|
| 257 | + if(substr($str, 0,3) == pack("CCC",0xef,0xbb,0xbf)) {
|
|
| 258 | + $str=substr($str, 3); |
|
| 259 | + } |
|
| 260 | + return $str; |
|
| 261 | 261 | } |
| 262 | 262 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | "\xc5\xb8" => "\x9f" |
| 115 | 115 | ); |
| 116 | 116 | |
| 117 | - static function toUTF8($text){
|
|
| 117 | + static function toUTF8($text) {
|
|
| 118 | 118 | /** |
| 119 | 119 | * Function Encoding::toUTF8 |
| 120 | 120 | * |
@@ -140,25 +140,25 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | */ |
| 142 | 142 | |
| 143 | - if(is_array($text)) |
|
| 143 | + if (is_array($text)) |
|
| 144 | 144 | {
|
| 145 | - foreach($text as $k => $v) |
|
| 145 | + foreach ($text as $k => $v) |
|
| 146 | 146 | {
|
| 147 | 147 | $text[$k] = self::toUTF8($v); |
| 148 | 148 | } |
| 149 | 149 | return $text; |
| 150 | - } elseif(is_string($text)) {
|
|
| 150 | + } elseif (is_string($text)) {
|
|
| 151 | 151 | |
| 152 | 152 | $max = strlen($text); |
| 153 | 153 | $buf = ""; |
| 154 | - for($i = 0; $i < $max; $i++){
|
|
| 154 | + for ($i = 0; $i < $max; $i++) {
|
|
| 155 | 155 | $c1 = $text{$i};
|
| 156 | - if($c1>="\xc0"){ //Should be converted to UTF8, if it's not UTF8 already
|
|
| 157 | - $c2 = $i+1 >= $max? "\x00" : $text{$i+1};
|
|
| 158 | - $c3 = $i+2 >= $max? "\x00" : $text{$i+2};
|
|
| 159 | - $c4 = $i+3 >= $max? "\x00" : $text{$i+3};
|
|
| 160 | - if($c1 >= "\xc0" & $c1 <= "\xdf"){ //looks like 2 bytes UTF8
|
|
| 161 | - if($c2 >= "\x80" && $c2 <= "\xbf"){ //yeah, almost sure it's UTF8 already
|
|
| 156 | + if ($c1 >= "\xc0") { //Should be converted to UTF8, if it's not UTF8 already
|
|
| 157 | + $c2 = $i + 1 >= $max ? "\x00" : $text{$i + 1};
|
|
| 158 | + $c3 = $i + 2 >= $max ? "\x00" : $text{$i + 2};
|
|
| 159 | + $c4 = $i + 3 >= $max ? "\x00" : $text{$i + 3};
|
|
| 160 | + if ($c1 >= "\xc0" & $c1 <= "\xdf") { //looks like 2 bytes UTF8
|
|
| 161 | + if ($c2 >= "\x80" && $c2 <= "\xbf") { //yeah, almost sure it's UTF8 already
|
|
| 162 | 162 | $buf .= $c1 . $c2; |
| 163 | 163 | $i++; |
| 164 | 164 | } else { //not valid UTF8. Convert it.
|
@@ -166,8 +166,8 @@ discard block |
||
| 166 | 166 | $cc2 = ($c1 & "\x3f") | "\x80"; |
| 167 | 167 | $buf .= $cc1 . $cc2; |
| 168 | 168 | } |
| 169 | - } elseif($c1 >= "\xe0" & $c1 <= "\xef"){ //looks like 3 bytes UTF8
|
|
| 170 | - if($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf"){ //yeah, almost sure it's UTF8 already
|
|
| 169 | + } elseif ($c1 >= "\xe0" & $c1 <= "\xef") { //looks like 3 bytes UTF8
|
|
| 170 | + if ($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf") { //yeah, almost sure it's UTF8 already
|
|
| 171 | 171 | $buf .= $c1 . $c2 . $c3; |
| 172 | 172 | $i = $i + 2; |
| 173 | 173 | } else { //not valid UTF8. Convert it.
|
@@ -175,8 +175,8 @@ discard block |
||
| 175 | 175 | $cc2 = ($c1 & "\x3f") | "\x80"; |
| 176 | 176 | $buf .= $cc1 . $cc2; |
| 177 | 177 | } |
| 178 | - } elseif($c1 >= "\xf0" & $c1 <= "\xf7"){ //looks like 4 bytes UTF8
|
|
| 179 | - if($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf" && $c4 >= "\x80" && $c4 <= "\xbf"){ //yeah, almost sure it's UTF8 already
|
|
| 178 | + } elseif ($c1 >= "\xf0" & $c1 <= "\xf7") { //looks like 4 bytes UTF8
|
|
| 179 | + if ($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf" && $c4 >= "\x80" && $c4 <= "\xbf") { //yeah, almost sure it's UTF8 already
|
|
| 180 | 180 | $buf .= $c1 . $c2 . $c3; |
| 181 | 181 | $i = $i + 2; |
| 182 | 182 | } else { //not valid UTF8. Convert it.
|
@@ -189,8 +189,8 @@ discard block |
||
| 189 | 189 | $cc2 = (($c1 & "\x3f") | "\x80"); |
| 190 | 190 | $buf .= $cc1 . $cc2; |
| 191 | 191 | } |
| 192 | - } elseif(($c1 & "\xc0") == "\x80"){ // needs conversion
|
|
| 193 | - if(isset(self::$win1252ToUtf8[ord($c1)])) { //found in Windows-1252 special cases
|
|
| 192 | + } elseif (($c1 & "\xc0") == "\x80") { // needs conversion
|
|
| 193 | + if (isset(self::$win1252ToUtf8[ord($c1)])) { //found in Windows-1252 special cases
|
|
| 194 | 194 | $buf .= self::$win1252ToUtf8[ord($c1)]; |
| 195 | 195 | } else {
|
| 196 | 196 | $cc1 = (chr(ord($c1) / 64) | "\xc0"); |
@@ -208,12 +208,12 @@ discard block |
||
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | static function toWin1252($text) {
|
| 211 | - if(is_array($text)) {
|
|
| 212 | - foreach($text as $k => $v) {
|
|
| 211 | + if (is_array($text)) {
|
|
| 212 | + foreach ($text as $k => $v) {
|
|
| 213 | 213 | $text[$k] = self::toWin1252($v); |
| 214 | 214 | } |
| 215 | 215 | return $text; |
| 216 | - } elseif(is_string($text)) {
|
|
| 216 | + } elseif (is_string($text)) {
|
|
| 217 | 217 | return utf8_decode(str_replace(array_keys(self::$utf8ToWin1252), array_values(self::$utf8ToWin1252), self::toUTF8($text))); |
| 218 | 218 | } else {
|
| 219 | 219 | return $text; |
@@ -228,16 +228,16 @@ discard block |
||
| 228 | 228 | return self::toWin1252($text); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - static function fixUTF8($text){
|
|
| 232 | - if(is_array($text)) {
|
|
| 233 | - foreach($text as $k => $v) {
|
|
| 231 | + static function fixUTF8($text) {
|
|
| 232 | + if (is_array($text)) {
|
|
| 233 | + foreach ($text as $k => $v) {
|
|
| 234 | 234 | $text[$k] = self::fixUTF8($v); |
| 235 | 235 | } |
| 236 | 236 | return $text; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | $last = ""; |
| 240 | - while($last <> $text){
|
|
| 240 | + while ($last <> $text) {
|
|
| 241 | 241 | $last = $text; |
| 242 | 242 | $text = self::toUTF8(utf8_decode(str_replace(array_keys(self::$utf8ToWin1252), array_values(self::$utf8ToWin1252), $text))); |
| 243 | 243 | } |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | return $text; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - static function UTF8FixWin1252Chars($text){
|
|
| 248 | + static function UTF8FixWin1252Chars($text) {
|
|
| 249 | 249 | // If you received an UTF-8 string that was converted from Windows-1252 as it was ISO8859-1 |
| 250 | 250 | // (ignoring Windows-1252 chars from 80 to 9F) use this function to fix it. |
| 251 | 251 | // See: http://en.wikipedia.org/wiki/Windows-1252 |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | return str_replace(array_keys(self::$brokenUtf8ToUtf8), array_values(self::$brokenUtf8ToUtf8), $text); |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - static function removeBOM($str=""){
|
|
| 257 | - if(substr($str, 0,3) == pack("CCC",0xef,0xbb,0xbf)) {
|
|
| 258 | - $str=substr($str, 3); |
|
| 256 | + static function removeBOM($str = "") {
|
|
| 257 | + if (substr($str, 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf)) {
|
|
| 258 | + $str = substr($str, 3); |
|
| 259 | 259 | } |
| 260 | 260 | return $str; |
| 261 | 261 | } |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | * Handles the output from downstream requests. |
| 254 | 254 | * @param object Request. |
| 255 | 255 | * @param string The output. |
| 256 | - * @return void |
|
| 256 | + * @return boolean |
|
| 257 | 257 | */ |
| 258 | 258 | public function requestOut($req, $output) { |
| 259 | 259 | $outlen = strlen($output); |
@@ -331,6 +331,9 @@ discard block |
||
| 331 | 331 | } |
| 332 | 332 | /** |
| 333 | 333 | * Handles the output from downstream requests. |
| 334 | + * @param stdClass $req |
|
| 335 | + * @param integer $appStatus |
|
| 336 | + * @param integer $protoStatus |
|
| 334 | 337 | * @return void |
| 335 | 338 | */ |
| 336 | 339 | public function endRequest($req, $appStatus, $protoStatus) { |
@@ -7,8 +7,8 @@ discard block |
||
| 7 | 7 | * @author Zorin Vasily <[email protected]> |
| 8 | 8 | */ |
| 9 | 9 | class FastCGIServerConnection extends Connection { |
| 10 | - protected $lowMark = 8; // initial value of the minimal amout of bytes in buffer |
|
| 11 | - protected $highMark = 0xFFFFFF; // initial value of the maximum amout of bytes in buffer |
|
| 10 | + protected $lowMark = 8; // initial value of the minimal amout of bytes in buffer |
|
| 11 | + protected $highMark = 0xFFFFFF; // initial value of the maximum amout of bytes in buffer |
|
| 12 | 12 | public $timeout = 180; |
| 13 | 13 | |
| 14 | 14 | protected $requests = array(); |
@@ -117,8 +117,7 @@ discard block |
||
| 117 | 117 | . ' (' . strlen($pad) . ')'); |
| 118 | 118 | |
| 119 | 119 | |
| 120 | - if ($type == self::FCGI_BEGIN_REQUEST) { |
|
| 121 | - ++Daemon::$process->reqCounter; |
|
| 120 | + if ($type == self::FCGI_BEGIN_REQUEST) {++Daemon::$process->reqCounter; |
|
| 122 | 121 | $u = unpack('nrole/Cflags', $this->content); |
| 123 | 122 | |
| 124 | 123 | $req = new stdClass(); |
@@ -130,7 +129,7 @@ discard block |
||
| 130 | 129 | $req->attrs->server = array(); |
| 131 | 130 | $req->attrs->files = array(); |
| 132 | 131 | $req->attrs->session = null; |
| 133 | - $req->attrs->role = self::$roles[$u['role']]; |
|
| 132 | + $req->attrs->role = self::$roles[$u['role']]; |
|
| 134 | 133 | $req->attrs->flags = $u['flags']; |
| 135 | 134 | $req->attrs->id = $this->header['reqid']; |
| 136 | 135 | $req->attrs->params_done = false; |
@@ -264,7 +263,7 @@ discard block |
||
| 264 | 263 | */ |
| 265 | 264 | // string bytes counter |
| 266 | 265 | $d = 0; |
| 267 | - while($d < $outlen){ |
|
| 266 | + while ($d < $outlen) { |
|
| 268 | 267 | |
| 269 | 268 | $ord_var_c = ord($output{$d}); |
| 270 | 269 | |
@@ -277,31 +276,31 @@ discard block |
||
| 277 | 276 | case (($ord_var_c & 0xE0) == 0xC0): |
| 278 | 277 | // characters U-00000080 - U-000007FF, mask 110XXXXX |
| 279 | 278 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 280 | - $d+=2; |
|
| 279 | + $d += 2; |
|
| 281 | 280 | break; |
| 282 | 281 | |
| 283 | 282 | case (($ord_var_c & 0xF0) == 0xE0): |
| 284 | 283 | // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
| 285 | 284 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 286 | - $d+=3; |
|
| 285 | + $d += 3; |
|
| 287 | 286 | break; |
| 288 | 287 | |
| 289 | 288 | case (($ord_var_c & 0xF8) == 0xF0): |
| 290 | 289 | // characters U-00010000 - U-001FFFFF, mask 11110XXX |
| 291 | 290 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 292 | - $d+=4; |
|
| 291 | + $d += 4; |
|
| 293 | 292 | break; |
| 294 | 293 | |
| 295 | 294 | case (($ord_var_c & 0xFC) == 0xF8): |
| 296 | 295 | // characters U-00200000 - U-03FFFFFF, mask 111110XX |
| 297 | 296 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 298 | - $d+=5; |
|
| 297 | + $d += 5; |
|
| 299 | 298 | break; |
| 300 | 299 | |
| 301 | 300 | case (($ord_var_c & 0xFE) == 0xFC): |
| 302 | 301 | // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
| 303 | 302 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 304 | - $d+=6; |
|
| 303 | + $d += 6; |
|
| 305 | 304 | break; |
| 306 | 305 | default: |
| 307 | 306 | $d++; |
@@ -112,9 +112,11 @@ discard block |
||
| 112 | 112 | $this->state = self::STATE_ROOT; |
| 113 | 113 | |
| 114 | 114 | |
| 115 | - if (0) Daemon::log('[DEBUG] FastCGI-record ' . $this->header['ttype'] . '). Request ID: ' . $rid |
|
| 115 | + if (0) { |
|
| 116 | + Daemon::log('[DEBUG] FastCGI-record ' . $this->header['ttype'] . '). Request ID: ' . $rid |
|
| 116 | 117 | . '. Content length: ' . $this->header['conlen'] . ' (' . strlen($this->content) . ') Padding length: ' . $this->header['padlen'] |
| 117 | 118 | . ' (' . strlen($pad) . ')'); |
| 119 | + } |
|
| 118 | 120 | |
| 119 | 121 | |
| 120 | 122 | if ($type == self::FCGI_BEGIN_REQUEST) { |
@@ -142,8 +144,7 @@ discard block |
||
| 142 | 144 | $req->queueId = $rid; |
| 143 | 145 | $req->conn = $this; |
| 144 | 146 | $this->requests[$rid] = $req; |
| 145 | - } |
|
| 146 | - elseif (isset($this->requests[$rid])) { |
|
| 147 | + } elseif (isset($this->requests[$rid])) { |
|
| 147 | 148 | $req = $this->requests[$rid]; |
| 148 | 149 | } else { |
| 149 | 150 | Daemon::log('Unexpected FastCGI-record #' . $this->header['type'] . ' (' . $this->header['ttype'] . '). Request ID: ' . $rid . '.'); |
@@ -152,8 +153,7 @@ discard block |
||
| 152 | 153 | |
| 153 | 154 | if ($type === self::FCGI_ABORT_REQUEST) { |
| 154 | 155 | $req->abort(); |
| 155 | - } |
|
| 156 | - elseif ($type === self::FCGI_PARAMS) { |
|
| 156 | + } elseif ($type === self::FCGI_PARAMS) { |
|
| 157 | 157 | if ($this->content === '') { |
| 158 | 158 | if (!isset($req->attrs->server['REQUEST_TIME'])) { |
| 159 | 159 | $req->attrs->server['REQUEST_TIME'] = time(); |
@@ -213,8 +213,7 @@ discard block |
||
| 213 | 213 | $p += $namelen + $vlen; |
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | - } |
|
| 217 | - elseif ($type === self::FCGI_STDIN) { |
|
| 216 | + } elseif ($type === self::FCGI_STDIN) { |
|
| 218 | 217 | if ($this->content === '') { |
| 219 | 218 | $req->attrs->stdin_done = true; |
| 220 | 219 | } |
@@ -234,11 +233,9 @@ discard block |
||
| 234 | 233 | |
| 235 | 234 | if ($char == 'G') { |
| 236 | 235 | $req->attrs->request += $req->attrs->get; |
| 237 | - } |
|
| 238 | - elseif ($char == 'P') { |
|
| 236 | + } elseif ($char == 'P') { |
|
| 239 | 237 | $req->attrs->request += $req->attrs->post; |
| 240 | - } |
|
| 241 | - elseif ($char == 'C') { |
|
| 238 | + } elseif ($char == 'C') { |
|
| 242 | 239 | $req->attrs->request += $req->attrs->cookie; |
| 243 | 240 | } |
| 244 | 241 | } |
@@ -349,8 +346,7 @@ discard block |
||
| 349 | 346 | |
| 350 | 347 | if ($protoStatus === -1) { |
| 351 | 348 | $this->close(); |
| 352 | - } |
|
| 353 | - elseif (!$this->pool->config->keepalive->value) { |
|
| 349 | + } elseif (!$this->pool->config->keepalive->value) { |
|
| 354 | 350 | $this->finish(); |
| 355 | 351 | } |
| 356 | 352 | } |
@@ -15,6 +15,9 @@ discard block |
||
| 15 | 15 | public $append; |
| 16 | 16 | public $path; |
| 17 | 17 | |
| 18 | + /** |
|
| 19 | + * @return string |
|
| 20 | + */ |
|
| 18 | 21 | public static function convertFlags($mode, $text = false) { |
| 19 | 22 | $plus = strpos($mode, '+') !== false; |
| 20 | 23 | $sync = strpos($mode, 's') !== false; |
@@ -55,6 +58,9 @@ discard block |
||
| 55 | 58 | eio_ftruncate($this->fd, $offset, $pri, $cb, $this); |
| 56 | 59 | } |
| 57 | 60 | |
| 61 | + /** |
|
| 62 | + * @param Closure $cb |
|
| 63 | + */ |
|
| 58 | 64 | public function stat($cb, $pri = EIO_PRI_DEFAULT) { |
| 59 | 65 | if (!$this->fd || $this->fd === -1) { |
| 60 | 66 | if ($cb) { |
@@ -77,6 +83,9 @@ discard block |
||
| 77 | 83 | } |
| 78 | 84 | } |
| 79 | 85 | |
| 86 | + /** |
|
| 87 | + * @param Closure $cb |
|
| 88 | + */ |
|
| 80 | 89 | public function statRefresh($cb, $pri = EIO_PRI_DEFAULT) { |
| 81 | 90 | if (!$this->fd || $this->fd === -1) { |
| 82 | 91 | if ($cb) { |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | if ($this->stat) { |
| 70 | 70 | call_user_func($cb, $this, $this->stat); |
| 71 | 71 | } else { |
| 72 | - eio_fstat($this->fd, $pri, function ($file, $stat) use ($cb) { |
|
| 72 | + eio_fstat($this->fd, $pri, function($file, $stat) use ($cb) { |
|
| 73 | 73 | $stat = FS::statPrepare($stat); |
| 74 | 74 | $file->stat = $stat; |
| 75 | 75 | call_user_func($cb, $file, $stat); |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | call_user_func($cb, $this, FS::statPrepare(fstat($this->fd))); |
| 89 | 89 | return; |
| 90 | 90 | } |
| 91 | - eio_fstat($this->fd, $pri, function ($file, $stat) use ($cb) { |
|
| 91 | + eio_fstat($this->fd, $pri, function($file, $stat) use ($cb) { |
|
| 92 | 92 | $stat = FS::statPrepare($stat); |
| 93 | 93 | $file->stat = $stat; |
| 94 | 94 | call_user_func($cb, $file, $stat); |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | if ($this->statvfs) { |
| 112 | 112 | call_user_func($cb, $this, $this->statvfs); |
| 113 | 113 | } else { |
| 114 | - eio_fstatvfs($this->fd, $pri, function ($file, $stat) use ($cb) { |
|
| 114 | + eio_fstatvfs($this->fd, $pri, function($file, $stat) use ($cb) { |
|
| 115 | 115 | $file->statvfs = $stat; |
| 116 | 116 | call_user_func($cb, $file, $stat); |
| 117 | 117 | }, $this); |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | $length, |
| 230 | 230 | $offset !== null ? $offset : $this->offset, |
| 231 | 231 | $pri, |
| 232 | - $cb ? $cb: $this->onRead, |
|
| 232 | + $cb ? $cb : $this->onRead, |
|
| 233 | 233 | $this |
| 234 | 234 | ); |
| 235 | 235 | return true; |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | } |
| 251 | 251 | static $chunkSize = 1024; |
| 252 | 252 | $ret = true; |
| 253 | - $handler = function ($file, $sent) use (&$ret, $outfd, $cb, &$handler, &$offset, &$length, $pri, $chunkSize) { |
|
| 253 | + $handler = function($file, $sent) use (&$ret, $outfd, $cb, &$handler, &$offset, &$length, $pri, $chunkSize) { |
|
| 254 | 254 | if (!$ret) { |
| 255 | 255 | call_user_func($cb, $file, false); |
| 256 | 256 | return; |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | $handler($this, -1); |
| 275 | 275 | return; |
| 276 | 276 | } |
| 277 | - $this->statRefresh(function ($file, $stat) use ($handler, &$length) { |
|
| 277 | + $this->statRefresh(function($file, $stat) use ($handler, &$length) { |
|
| 278 | 278 | $length = $stat['size']; |
| 279 | 279 | $handler($file, -1); |
| 280 | 280 | }, $pri); |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | } |
| 313 | 313 | return false; |
| 314 | 314 | } |
| 315 | - $this->statRefresh(function ($file, $stat) use ($cb, $pri) { |
|
| 315 | + $this->statRefresh(function($file, $stat) use ($cb, $pri) { |
|
| 316 | 316 | if (!$stat) { |
| 317 | 317 | if ($cb) { |
| 318 | 318 | call_user_func($cb, $file, false); |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | $offset = 0; |
| 323 | 323 | $buf = ''; |
| 324 | 324 | $size = $stat['size']; |
| 325 | - $handler = function ($file, $data) use ($cb, &$handler, $size, &$offset, $pri, &$buf) { |
|
| 325 | + $handler = function($file, $data) use ($cb, &$handler, $size, &$offset, $pri, &$buf) { |
|
| 326 | 326 | $buf .= $data; |
| 327 | 327 | $offset += strlen($data); |
| 328 | 328 | $len = min($file->chunkSize, $size - $offset); |
@@ -345,14 +345,14 @@ discard block |
||
| 345 | 345 | } |
| 346 | 346 | return false; |
| 347 | 347 | } |
| 348 | - $this->statRefresh(function ($file, $stat) use ($cb, $chunkcb, $pri) { |
|
| 348 | + $this->statRefresh(function($file, $stat) use ($cb, $chunkcb, $pri) { |
|
| 349 | 349 | if (!$stat) { |
| 350 | 350 | call_user_func($cb, $file, false); |
| 351 | 351 | return; |
| 352 | 352 | } |
| 353 | 353 | $offset = 0; |
| 354 | 354 | $size = $stat['size']; |
| 355 | - $handler = function ($file, $data) use ($cb, $chunkcb, &$handler, $size, &$offset, $pri) { |
|
| 355 | + $handler = function($file, $data) use ($cb, $chunkcb, &$handler, $size, &$offset, $pri) { |
|
| 356 | 356 | call_user_func($chunkcb, $file, $data); |
| 357 | 357 | $offset += strlen($data); |
| 358 | 358 | $len = min($file->chunkSize, $size - $offset); |
@@ -86,6 +86,10 @@ discard block |
||
| 86 | 86 | return $stat; |
| 87 | 87 | |
| 88 | 88 | } |
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param Closure $cb |
|
| 92 | + */ |
|
| 89 | 93 | public static function stat($path, $cb, $pri = EIO_PRI_DEFAULT) { |
| 90 | 94 | if (!self::$supported) { |
| 91 | 95 | call_user_func($cb, $path, FS::statPrepare(@stat($path))); |
@@ -182,6 +186,10 @@ discard block |
||
| 182 | 186 | return eio_mkdir($path, $mode, $pri, $cb, $path); |
| 183 | 187 | } |
| 184 | 188 | |
| 189 | + /** |
|
| 190 | + * @param string $path |
|
| 191 | + * @param Closure $cb |
|
| 192 | + */ |
|
| 185 | 193 | public static function readdir($path, $cb = null, $flags, $pri = EIO_PRI_DEFAULT) { |
| 186 | 194 | if (!FS::$supported) { |
| 187 | 195 | $r = glob($path); |
@@ -233,6 +241,9 @@ discard block |
||
| 233 | 241 | return eio_chown($path, $uid, $gid, $pri, $cb, $path); |
| 234 | 242 | } |
| 235 | 243 | |
| 244 | + /** |
|
| 245 | + * @param Closure $cb |
|
| 246 | + */ |
|
| 236 | 247 | public static function readfile($path, $cb, $pri = EIO_PRI_DEFAULT) { |
| 237 | 248 | if (!FS::$supported) { |
| 238 | 249 | call_user_func($cb, $path, file_get_contents($path)); |
@@ -247,6 +258,9 @@ discard block |
||
| 247 | 258 | }, null, $pri); |
| 248 | 259 | } |
| 249 | 260 | |
| 261 | + /** |
|
| 262 | + * @param Closure $chunkcb |
|
| 263 | + */ |
|
| 250 | 264 | public static function readfileChunked($path, $cb, $chunkcb, $pri = EIO_PRI_DEFAULT) { |
| 251 | 265 | if (!FS::$supported) { |
| 252 | 266 | call_user_func($chunkcb, $path, $r = readfile($path)); |
@@ -266,6 +280,10 @@ discard block |
||
| 266 | 280 | return tempnam($dir, $prefix); |
| 267 | 281 | } |
| 268 | 282 | |
| 283 | + /** |
|
| 284 | + * @param string $flags |
|
| 285 | + * @param Closure $cb |
|
| 286 | + */ |
|
| 269 | 287 | public static function open($path, $flags, $cb, $mode = null, $pri = EIO_PRI_DEFAULT) { |
| 270 | 288 | if (self::$supported) { |
| 271 | 289 | $fdCacheKey = $path . "\x00" . $flags; |
@@ -39,8 +39,8 @@ discard block |
||
| 39 | 39 | self::$fd = eio_get_event_stream(); |
| 40 | 40 | self::$ev = new Event(Daemon::$process->eventBase, self::$fd, Event::READ | Event::PERSIST, function ($fd, $events, $arg) { |
| 41 | 41 | while (eio_nreqs()) { |
| 42 | - eio_poll(); |
|
| 43 | - } |
|
| 42 | + eio_poll(); |
|
| 43 | + } |
|
| 44 | 44 | }); |
| 45 | 45 | self::$ev->add(); |
| 46 | 46 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | return; |
| 51 | 51 | } |
| 52 | 52 | while (eio_nreqs()) { |
| 53 | - eio_poll(); |
|
| 53 | + eio_poll(); |
|
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | public static $fdCache; |
| 25 | 25 | public static $fdCacheSize = 128; |
| 26 | 26 | public static function init() { |
| 27 | - if (!self::$supported = Daemon::loadModuleIfAbsent('eio')) { |
|
| 27 | + if (!self::$supported = Daemon::loadModuleIfAbsent('eio')) { |
|
| 28 | 28 | Daemon::log('FS: missing pecl-eio, Filesystem I/O performance compromised. Consider installing pecl-eio.'); |
| 29 | 29 | return; |
| 30 | 30 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | } |
| 38 | 38 | self::updateConfig(); |
| 39 | 39 | self::$fd = eio_get_event_stream(); |
| 40 | - self::$ev = new Event(Daemon::$process->eventBase, self::$fd, Event::READ | Event::PERSIST, function ($fd, $events, $arg) { |
|
| 40 | + self::$ev = new Event(Daemon::$process->eventBase, self::$fd, Event::READ | Event::PERSIST, function($fd, $events, $arg) { |
|
| 41 | 41 | while (eio_nreqs()) { |
| 42 | 42 | eio_poll(); |
| 43 | 43 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | call_user_func($cb, $path, FS::statPrepare(@stat($path))); |
| 92 | 92 | return; |
| 93 | 93 | } |
| 94 | - return eio_stat($path, $pri, function($path, $stat) use ($cb) {call_user_func($cb, $path, FS::statPrepare($stat));}, $path); |
|
| 94 | + return eio_stat($path, $pri, function($path, $stat) use ($cb) {call_user_func($cb, $path, FS::statPrepare($stat)); }, $path); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | public static function unlink($path, $cb = null, $pri = EIO_PRI_DEFAULT) { |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | call_user_func($cb, $path, FS::statPrepare(lstat($path))); |
| 119 | 119 | return; |
| 120 | 120 | } |
| 121 | - return eio_lstat($path, $pri, function($path, $stat) use ($cb) {call_user_func($cb, $path, FS::statPrepare($stat));}, $path); |
|
| 121 | + return eio_lstat($path, $pri, function($path, $stat) use ($cb) {call_user_func($cb, $path, FS::statPrepare($stat)); }, $path); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | public static function realpath($path, $cb, $pri = EIO_PRI_DEFAULT) { |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | return eio_mkdir($path, $mode, $pri, $cb, $path); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - public static function readdir($path, $cb = null, $flags, $pri = EIO_PRI_DEFAULT) { |
|
| 185 | + public static function readdir($path, $cb = null, $flags, $pri = EIO_PRI_DEFAULT) { |
|
| 186 | 186 | if (!FS::$supported) { |
| 187 | 187 | $r = glob($path); |
| 188 | 188 | if ($cb) { |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | call_user_func($cb, $path, false); |
| 212 | 212 | return; |
| 213 | 213 | } |
| 214 | - FS::open($path, 'r', function ($file) use ($cb, $path, $pri, $outfd, $offset, $length) { |
|
| 214 | + FS::open($path, 'r', function($file) use ($cb, $path, $pri, $outfd, $offset, $length) { |
|
| 215 | 215 | if (!$file) { |
| 216 | 216 | call_user_func($cb, $path, false); |
| 217 | 217 | return; |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | call_user_func($cb, $path, file_get_contents($path)); |
| 239 | 239 | return; |
| 240 | 240 | } |
| 241 | - FS::open($path, 'r', function ($file) use ($cb, $pri, $path) { |
|
| 241 | + FS::open($path, 'r', function($file) use ($cb, $pri, $path) { |
|
| 242 | 242 | if (!$file) { |
| 243 | 243 | call_user_func($cb, $path, false); |
| 244 | 244 | return; |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | call_user_func($cb, $r !== false); |
| 254 | 254 | return; |
| 255 | 255 | } |
| 256 | - FS::open($path, 'r', function ($file) use ($cb, $chunkcb, $pri) { |
|
| 256 | + FS::open($path, 'r', function($file) use ($cb, $chunkcb, $pri) { |
|
| 257 | 257 | if (!$file) { |
| 258 | 258 | call_user_func($cb, $file->path, false); |
| 259 | 259 | return; |
@@ -283,8 +283,8 @@ discard block |
||
| 283 | 283 | $item = FS::$fdCache->put($fdCacheKey, null); |
| 284 | 284 | $item->addListener($cb); |
| 285 | 285 | } |
| 286 | - return eio_open($path, $flags , $mode, |
|
| 287 | - $pri, function ($arg, $fd) use ($cb, $path, $flags, $fdCacheKey, $noncache) { |
|
| 286 | + return eio_open($path, $flags, $mode, |
|
| 287 | + $pri, function($arg, $fd) use ($cb, $path, $flags, $fdCacheKey, $noncache) { |
|
| 288 | 288 | |
| 289 | 289 | if (!$fd) { |
| 290 | 290 | if ($noncache) { |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | * Creates Request. |
| 39 | 39 | * @param object Request. |
| 40 | 40 | * @param object Upstream application instance. |
| 41 | - * @return object Request. |
|
| 41 | + * @return GameMonitorHTTPRequest Request. |
|
| 42 | 42 | */ |
| 43 | 43 | public function beginRequest($req, $upstream) { |
| 44 | 44 | return new GameMonitorHTTPRequest($this, $upstream, $req); |
@@ -63,10 +63,10 @@ discard block |
||
| 63 | 63 | $set['players'] = $job->results['players']; |
| 64 | 64 | $set['latency'] = $job->results['latency']; |
| 65 | 65 | $set['atime'] = time(); |
| 66 | - if (0) Daemon::log('Updated server ('.round(memory_get_usage(true)/1024/1024, 5).'): '.$server['address']. ' latency = '.round($set['latency'] * 1000, 2).' ==== ' |
|
| 66 | + if (0) Daemon::log('Updated server (' . round(memory_get_usage(true) / 1024 / 1024, 5) . '): ' . $server['address'] . ' latency = ' . round($set['latency'] * 1000, 2) . ' ==== ' |
|
| 67 | 67 | . (isset($server['atime']) ? |
| 68 | 68 | round($set['atime'] - $server['atime']) . ' secs. from last update.' |
| 69 | - : ' =---= '.json_encode($server)) |
|
| 69 | + : ' =---= ' . json_encode($server)) |
|
| 70 | 70 | ); |
| 71 | 71 | try { |
| 72 | 72 | $app->servers->upsert(array('_id' => $server['_id']), array('$set' => $set)); |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | $app->jobMap[$server['address']] = $job; |
| 79 | 79 | //Daemon::log('Added job for '.$server['address']); |
| 80 | 80 | |
| 81 | - $job('info', function ($jobname, $job) use ($app, $server) { |
|
| 82 | - $app->client->requestInfo($server['address'], function ($conn, $result) use ($app, $server, $jobname, $job) { |
|
| 81 | + $job('info', function($jobname, $job) use ($app, $server) { |
|
| 82 | + $app->client->requestInfo($server['address'], function($conn, $result) use ($app, $server, $jobname, $job) { |
|
| 83 | 83 | |
| 84 | - $job('players', function ($jobname, $job) use ($app, $server, $conn) { |
|
| 84 | + $job('players', function($jobname, $job) use ($app, $server, $conn) { |
|
| 85 | 85 | |
| 86 | - $conn->requestPlayers(function ($conn, $result) use ($app,$jobname, $job) { |
|
| 86 | + $conn->requestPlayers(function($conn, $result) use ($app, $jobname, $job) { |
|
| 87 | 87 | |
| 88 | 88 | $job->setResult($jobname, $result); |
| 89 | 89 | $conn->finish(); |
@@ -96,9 +96,9 @@ discard block |
||
| 96 | 96 | }); |
| 97 | 97 | }); |
| 98 | 98 | |
| 99 | - $job('latency', function ($jobname, $job) use ($app, $server) { |
|
| 99 | + $job('latency', function($jobname, $job) use ($app, $server) { |
|
| 100 | 100 | |
| 101 | - $app->client->ping($server['address'], function ($conn, $result) use ($app, $jobname, $job) { |
|
| 101 | + $app->client->ping($server['address'], function($conn, $result) use ($app, $jobname, $job) { |
|
| 102 | 102 | |
| 103 | 103 | $job->setResult($jobname, $result); |
| 104 | 104 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | gc_collect_cycles(); |
| 117 | 117 | $app = $this; |
| 118 | 118 | $amount = 1000 - sizeof($this->jobMap); |
| 119 | - Daemon::log('amount: '.$amount); |
|
| 119 | + Daemon::log('amount: ' . $amount); |
|
| 120 | 120 | if ($amount <= 0) { |
| 121 | 121 | return; |
| 122 | 122 | } |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | )), |
| 140 | 140 | //'fields' => '_id,atime,address', |
| 141 | - 'limit' => - max($amount, 100), |
|
| 141 | + 'limit' => -max($amount, 100), |
|
| 142 | 142 | 'sort' => array('atime' => 1), |
| 143 | 143 | )); |
| 144 | 144 | } |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | public function onReady() { |
| 151 | 151 | if ($this->isEnabled()) { |
| 152 | - $this->updateTimer = setTimeout(function ($timer) { |
|
| 152 | + $this->updateTimer = setTimeout(function($timer) { |
|
| 153 | 153 | $this->updateAllServers(); |
| 154 | 154 | $timer->timeout(2e6); |
| 155 | 155 | }, 1); |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | |
| 197 | 197 | $job('getServers', function($name, $job) use ($req) { // registering job named 'pingjob' |
| 198 | 198 | |
| 199 | - $req->appInstance->servers->find(function ($cursor) use ($name, $job) { |
|
| 199 | + $req->appInstance->servers->find(function($cursor) use ($name, $job) { |
|
| 200 | 200 | $job->setResult($name, $cursor->items); |
| 201 | 201 | }); |
| 202 | 202 | }); |
@@ -63,11 +63,13 @@ |
||
| 63 | 63 | $set['players'] = $job->results['players']; |
| 64 | 64 | $set['latency'] = $job->results['latency']; |
| 65 | 65 | $set['atime'] = time(); |
| 66 | - if (0) Daemon::log('Updated server ('.round(memory_get_usage(true)/1024/1024, 5).'): '.$server['address']. ' latency = '.round($set['latency'] * 1000, 2).' ==== ' |
|
| 66 | + if (0) { |
|
| 67 | + Daemon::log('Updated server ('.round(memory_get_usage(true)/1024/1024, 5).'): '.$server['address']. ' latency = '.round($set['latency'] * 1000, 2).' ==== ' |
|
| 67 | 68 | . (isset($server['atime']) ? |
| 68 | 69 | round($set['atime'] - $server['atime']) . ' secs. from last update.' |
| 69 | 70 | : ' =---= '.json_encode($server)) |
| 70 | 71 | ); |
| 72 | + } |
|
| 71 | 73 | try { |
| 72 | 74 | $app->servers->upsert(array('_id' => $server['_id']), array('$set' => $set)); |
| 73 | 75 | } catch (MongoException $e) { |
@@ -105,6 +105,9 @@ discard block |
||
| 105 | 105 | $this->parseParams(); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | + /** |
|
| 109 | + * @param Closure $cb |
|
| 110 | + */ |
|
| 108 | 111 | public function sendfile($path, $cb, $pri = EIO_PRI_DEFAULT) { |
| 109 | 112 | $req = $this; |
| 110 | 113 | if ($req->state === self::STATE_FINISHED) { |
@@ -122,6 +125,10 @@ discard block |
||
| 122 | 125 | } |
| 123 | 126 | $first = true; |
| 124 | 127 | FS::readfileChunked($path, $cb, |
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @param Closure $chunk |
|
| 131 | + */ |
|
| 125 | 132 | function($file, $chunk) use ($req, &$first) { // readed chunk |
| 126 | 133 | if ($first) { |
| 127 | 134 | try { |
@@ -137,7 +144,7 @@ discard block |
||
| 137 | 144 | /** |
| 138 | 145 | * Called by call() to check if ready |
| 139 | 146 | * @todo protected? |
| 140 | - * @return void |
|
| 147 | + * @return boolean |
|
| 141 | 148 | */ |
| 142 | 149 | public function checkIfReady() { |
| 143 | 150 | if ( |
@@ -484,7 +491,7 @@ discard block |
||
| 484 | 491 | * Send HTTP-status |
| 485 | 492 | * @throws RequestHeadersAlreadySent |
| 486 | 493 | * @param int Code |
| 487 | - * @return void |
|
| 494 | + * @return boolean |
|
| 488 | 495 | */ |
| 489 | 496 | public function status($code = 200) { |
| 490 | 497 | if (!isset(self::$codes[$code])) { |
@@ -522,6 +529,7 @@ discard block |
||
| 522 | 529 | * @param string. Optional. Path. Default is empty string. |
| 523 | 530 | * @param boolean. Optional. Secure. Default is false. |
| 524 | 531 | * @param boolean. Optional. HTTPOnly. Default is false. |
| 532 | + * @param string $name |
|
| 525 | 533 | * @return void |
| 526 | 534 | * @throws RequestHeadersAlreadySent |
| 527 | 535 | */ |
@@ -607,6 +615,7 @@ discard block |
||
| 607 | 615 | |
| 608 | 616 | /** |
| 609 | 617 | * @todo description missing |
| 618 | + * @param string $value |
|
| 610 | 619 | */ |
| 611 | 620 | public function parseSize($value) { |
| 612 | 621 | $l = strtolower(substr($value, -1)); |
@@ -873,7 +882,7 @@ discard block |
||
| 873 | 882 | |
| 874 | 883 | /** |
| 875 | 884 | * Read request body from the file given in REQUEST_BODY_FILE parameter. |
| 876 | - * @return void |
|
| 885 | + * @return false|null |
|
| 877 | 886 | */ |
| 878 | 887 | public function readBodyFile() { |
| 879 | 888 | if (!isset($this->attrs->server['REQUEST_BODY_FILE'])) { |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * Status codes |
| 14 | 14 | * @var array |
| 15 | 15 | */ |
| 16 | - private static $codes = array ( |
|
| 16 | + private static $codes = array( |
|
| 17 | 17 | 100 => 'Continue', |
| 18 | 18 | 101 => 'Switching Protocols', |
| 19 | 19 | 200 => 'OK', |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | $URLprefix = $this->attrs->server['REQUEST_PREPARED_UPLOADS_URL_PREFIX']; |
| 243 | 243 | $l = strlen($URLprefix); |
| 244 | 244 | foreach (array('PHP_SELF', 'REQUEST_URI', 'SCRIPT_NAME', 'DOCUMENT_URI') as $k) { |
| 245 | - if (!isset($this->attrs->server[$k])) {continue;} |
|
| 245 | + if (!isset($this->attrs->server[$k])) {continue; } |
|
| 246 | 246 | if (strncmp($this->attrs->server[$k], $URLprefix, $l) === 0) { |
| 247 | 247 | $this->attrs->server[$k] = substr($this->attrs->server[$k], $l - 1); |
| 248 | 248 | } |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | if ($this->oldFashionUploadFP) { |
| 273 | 273 | $file['fp'] = fopen($file['tmp_name'], 'c+'); |
| 274 | 274 | } else { |
| 275 | - FS::open($file['tmp_name'], 'c+', function ($fp) use (&$file) { |
|
| 275 | + FS::open($file['tmp_name'], 'c+', function($fp) use (&$file) { |
|
| 276 | 276 | if (!$fp) { |
| 277 | 277 | return; |
| 278 | 278 | } |
@@ -529,8 +529,8 @@ discard block |
||
| 529 | 529 | $this->header( |
| 530 | 530 | 'Set-Cookie: ' . $name . '=' . rawurlencode($value) |
| 531 | 531 | . (empty($domain) ? '' : '; Domain=' . $domain) |
| 532 | - . (empty($maxage) ? '' : '; Max-Age='.$maxage) |
|
| 533 | - . (empty($path) ? '' : '; Path='.$path) |
|
| 532 | + . (empty($maxage) ? '' : '; Max-Age=' . $maxage) |
|
| 533 | + . (empty($path) ? '' : '; Path=' . $path) |
|
| 534 | 534 | . (!$secure ? '' : '; Secure') |
| 535 | 535 | . (!$HTTPOnly ? '' : '; HttpOnly'), false); |
| 536 | 536 | } |
@@ -570,17 +570,17 @@ discard block |
||
| 570 | 570 | if (!isset($ctype['charset'])) { |
| 571 | 571 | $ctype['charset'] = $this->upstream->pool->config->defaultcharset->value; |
| 572 | 572 | |
| 573 | - $s = $e[0].': '; |
|
| 573 | + $s = $e[0] . ': '; |
|
| 574 | 574 | $i = 0; |
| 575 | 575 | foreach ($ctype as $k => $v) { |
| 576 | - $s .= ($i > 0 ? '; ' : '') . $k. ($v !== '' ? '=' . $v : ''); |
|
| 576 | + $s .= ($i > 0 ? '; ' : '') . $k . ($v !== '' ? '=' . $v : ''); |
|
| 577 | 577 | ++$i; |
| 578 | 578 | } |
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | if ($k === 'SET_COOKIE') { |
| 583 | - $k .= '_'.++$this->cookieNum; |
|
| 583 | + $k .= '_' . ++$this->cookieNum; |
|
| 584 | 584 | } |
| 585 | 585 | elseif ( |
| 586 | 586 | !$replace |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | if (FS::$supported) { |
| 704 | 704 | $this->upstream->lockRead(); |
| 705 | 705 | } |
| 706 | - FS::open($this->attrs->files[$name]['tmp_name'], 'c+', function ($fp) use ($req, $name) { |
|
| 706 | + FS::open($this->attrs->files[$name]['tmp_name'], 'c+', function($fp) use ($req, $name) { |
|
| 707 | 707 | if (!$fp) { |
| 708 | 708 | $req->attrs->files[$name]['error'] = UPLOAD_ERR_CANT_WRITE; |
| 709 | 709 | } |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | * @param string The destination of the moved file. |
| 865 | 865 | * @return boolean Success. |
| 866 | 866 | */ |
| 867 | - public function moveUploadedFile($filename,$dest) { |
|
| 867 | + public function moveUploadedFile($filename, $dest) { |
|
| 868 | 868 | if (!$this->isUploadedFile($filename)) { |
| 869 | 869 | return false; |
| 870 | 870 | } |
@@ -880,7 +880,7 @@ discard block |
||
| 880 | 880 | return false; |
| 881 | 881 | } |
| 882 | 882 | FS::readfileChunked($this->attrs->server['REQUEST_BODY_FILE'], |
| 883 | - function ($file, $success) { |
|
| 883 | + function($file, $success) { |
|
| 884 | 884 | $this->attrs->stdin_done = true; |
| 885 | 885 | if ($this->sleepTime === 0) { |
| 886 | 886 | $this->wakeup(); |
@@ -902,7 +902,7 @@ discard block |
||
| 902 | 902 | public static function parse_str($s, &$var, $header = false) { |
| 903 | 903 | static $cb; |
| 904 | 904 | if ($cb === NULL) { |
| 905 | - $cb = function ($m) { |
|
| 905 | + $cb = function($m) { |
|
| 906 | 906 | return urlencode(html_entity_decode('&#' . hexdec($m[1]) . ';', ENT_NOQUOTES, 'utf-8')); |
| 907 | 907 | }; |
| 908 | 908 | } |
@@ -910,7 +910,7 @@ discard block |
||
| 910 | 910 | $s = strtr($s, HTTPRequest::$hvaltr); |
| 911 | 911 | } |
| 912 | 912 | if ( |
| 913 | - (stripos($s,'%u') !== false) |
|
| 913 | + (stripos($s, '%u') !== false) |
|
| 914 | 914 | && preg_match('~(%u[a-f\d]{4}|%[c-f][a-f\d](?!%[89a-f][a-f\d]))~is', $s, $m) |
| 915 | 915 | ) { |
| 916 | 916 | $s = preg_replace_callback('~%(u[a-f\d]{4}|[a-f\d]{2})~i', $cb, $s); |
@@ -581,8 +581,7 @@ discard block |
||
| 581 | 581 | |
| 582 | 582 | if ($k === 'SET_COOKIE') { |
| 583 | 583 | $k .= '_'.++$this->cookieNum; |
| 584 | - } |
|
| 585 | - elseif ( |
|
| 584 | + } elseif ( |
|
| 586 | 585 | !$replace |
| 587 | 586 | && isset($this->headers[$k]) |
| 588 | 587 | ) { |
@@ -593,8 +592,7 @@ discard block |
||
| 593 | 592 | |
| 594 | 593 | if ($k === 'CONTENT_LENGTH') { |
| 595 | 594 | $this->contentLength = (int) $e[1]; |
| 596 | - } |
|
| 597 | - elseif ($k === 'LOCATION') { |
|
| 595 | + } elseif ($k === 'LOCATION') { |
|
| 598 | 596 | $this->status(301); |
| 599 | 597 | } |
| 600 | 598 | |
@@ -719,8 +717,7 @@ discard block |
||
| 719 | 717 | } else { |
| 720 | 718 | $this->attrs->post[$this->mpartcondisp['name']] = ''; |
| 721 | 719 | } |
| 722 | - } |
|
| 723 | - elseif ( |
|
| 720 | + } elseif ( |
|
| 724 | 721 | ($e[0] == 'CONTENT_TYPE') |
| 725 | 722 | && isset($e[1]) |
| 726 | 723 | ) { |
@@ -758,8 +755,7 @@ discard block |
||
| 758 | 755 | && isset($this->mpartcondisp['name']) |
| 759 | 756 | ) { |
| 760 | 757 | $this->attrs->post[$this->mpartcondisp['name']] .= $chunk; |
| 761 | - } |
|
| 762 | - elseif ( |
|
| 758 | + } elseif ( |
|
| 763 | 759 | ($this->mpartstate === self::MPSTATE_UPLOAD) |
| 764 | 760 | && isset($this->mpartcondisp['filename']) |
| 765 | 761 | ) { |
@@ -799,8 +795,7 @@ discard block |
||
| 799 | 795 | && isset($this->mpartcondisp['name']) |
| 800 | 796 | ) { |
| 801 | 797 | $this->attrs->post[$this->mpartcondisp['name']] .= $chunk; |
| 802 | - } |
|
| 803 | - elseif ( |
|
| 798 | + } elseif ( |
|
| 804 | 799 | ($this->mpartstate === self::MPSTATE_UPLOAD) |
| 805 | 800 | && isset($this->mpartcondisp['filename']) |
| 806 | 801 | ) { |
@@ -228,7 +228,10 @@ |
||
| 228 | 228 | |
| 229 | 229 | /** |
| 230 | 230 | * Handles the output from downstream requests. |
| 231 | - * @return boolean Succcess. |
|
| 231 | + * @param stdClass $req |
|
| 232 | + * @param integer $appStatus |
|
| 233 | + * @param integer $protoStatus |
|
| 234 | + * @return boolean|null Succcess. |
|
| 232 | 235 | */ |
| 233 | 236 | public function endRequest($req, $appStatus, $protoStatus) { |
| 234 | 237 | if ($protoStatus === -1) { |
@@ -8,8 +8,8 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | class HTTPServerConnection extends Connection { |
| 11 | - protected $initialLowMark = 1; // initial value of the minimal amout of bytes in buffer |
|
| 12 | - protected $initialHighMark = 0xFFFFFF; // initial value of the maximum amout of bytes in buffer |
|
| 11 | + protected $initialLowMark = 1; // initial value of the minimal amout of bytes in buffer |
|
| 12 | + protected $initialHighMark = 0xFFFFFF; // initial value of the maximum amout of bytes in buffer |
|
| 13 | 13 | public $timeout = 45; |
| 14 | 14 | |
| 15 | 15 | public $req; |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | } else { |
| 80 | 80 | if (!$this->req) { |
| 81 | 81 | if ($buf !== '') { |
| 82 | - Daemon::log('Unexpected input (HTTP request): '.Debug::dump($buf)); |
|
| 82 | + Daemon::log('Unexpected input (HTTP request): ' . Debug::dump($buf)); |
|
| 83 | 83 | } |
| 84 | 84 | return; |
| 85 | 85 | } |
@@ -157,11 +157,11 @@ discard block |
||
| 157 | 157 | if ($req instanceof stdClass) { |
| 158 | 158 | $this->endRequest($req, 0, 0); |
| 159 | 159 | } else { |
| 160 | - if ($this->pool->config->sendfile->value && (!$this->pool->config->sendfileonlybycommand->value || isset($req->attrs->server['USE_SENDFILE'])) |
|
| 160 | + if ($this->pool->config->sendfile->value && (!$this->pool->config->sendfileonlybycommand->value || isset($req->attrs->server['USE_SENDFILE'])) |
|
| 161 | 161 | && !isset($req->attrs->server['DONT_USE_SENDFILE']) |
| 162 | 162 | ) { |
| 163 | 163 | $fn = FS::tempnam($this->pool->config->sendfiledir->value, $this->pool->config->sendfileprefix->value); |
| 164 | - FS::open($fn, 'wb', function ($file) use ($req) { |
|
| 164 | + FS::open($fn, 'wb', function($file) use ($req) { |
|
| 165 | 165 | $req->sendfp = $file; |
| 166 | 166 | }); |
| 167 | 167 | $req->header('X-Sendfile: ' . $fn); |
@@ -116,12 +116,10 @@ discard block |
||
| 116 | 116 | if (isset($e[1])) { |
| 117 | 117 | $currentHeader = 'HTTP_' . strtoupper(strtr($e[0], HTTPRequest::$htr)); |
| 118 | 118 | $req->attrs->server[$currentHeader] = $e[1]; |
| 119 | - } |
|
| 120 | - elseif ($e[0][0] === "\t" || $e[0][0] === "\x20") |
|
| 119 | + } elseif ($e[0][0] === "\t" || $e[0][0] === "\x20") |
|
| 121 | 120 | { // multiline header continued |
| 122 | 121 | $req->attrs->server[$currentHeader] .= $e[0]; |
| 123 | - } |
|
| 124 | - else |
|
| 122 | + } else |
|
| 125 | 123 | { // whatever client speaks is not HTTP anymore |
| 126 | 124 | $this->finish(); |
| 127 | 125 | return; |
@@ -168,8 +166,7 @@ discard block |
||
| 168 | 166 | } |
| 169 | 167 | $this->state = self::STATE_CONTENT; |
| 170 | 168 | } |
| 171 | - } |
|
| 172 | - else { |
|
| 169 | + } else { |
|
| 173 | 170 | $this->bufHead = $buf; |
| 174 | 171 | goto start; |
| 175 | 172 | } |
@@ -197,11 +194,9 @@ discard block |
||
| 197 | 194 | $char = $this->pool->variablesOrder[$i]; |
| 198 | 195 | if ($char == 'G') { |
| 199 | 196 | $req->attrs->request += $req->attrs->get; |
| 200 | - } |
|
| 201 | - elseif ($char == 'P') { |
|
| 197 | + } elseif ($char == 'P') { |
|
| 202 | 198 | $req->attrs->request += $req->attrs->post; |
| 203 | - } |
|
| 204 | - elseif ($char == 'C') { |
|
| 199 | + } elseif ($char == 'C') { |
|
| 205 | 200 | $req->attrs->request += $req->attrs->cookie; |
| 206 | 201 | } |
| 207 | 202 | } |