3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace ProxyChecker; class ProxyChecker { private $proxyCheckUrl; private $config = array( 'timeout' => 10, 'check' => array('get', 'post', 'cookie', 'referer', 'user_agent'), ); public function __construct($proxyCheckUrl, array $config = array()) { $this->proxyCheckUrl = $proxyCheckUrl; $this->setConfig($config); } public function setConfig(array $config) { $this->config = array_merge($this->config, $config); } public function checkProxies(array $proxies) { $results = array(); foreach ($proxies as $proxy) { try { $results[$proxy] = $this->checkProxy($proxy); } catch (\Exception $e) { $results[$proxy]['error'] = $e->getMessage(); } } return $results; } public function checkProxy($proxy) { list($content, $info) = $this->getProxyContent($proxy); return $this->checkProxyContent($content, $info); } private function getProxyContent($proxy) { @list($proxyIp, $proxyPassword, $proxyType) = explode(',', $proxy); $ch = \curl_init(); $url = $this->proxyCheckUrl; // check query if (in_array('get', $this->config['check'])) { $url .= '?q=query'; } $options = array( CURLOPT_URL => $url, CURLOPT_PROXY => $proxyIp, CURLOPT_HEADER => true, CURLOPT_TIMEOUT => $this->config['timeout'], CURLOPT_CONNECTTIMEOUT => $this->config['timeout'], CURLOPT_RETURNTRANSFER => true ); if (!empty($proxyPassword)) { $options[CURLOPT_PROXYAUTH] = CURLAUTH_BASIC; $options[CURLOPT_PROXYUSERPWD] = $proxyPassword; } // check post if (in_array('post', $this->config['check'])) { $options[CURLOPT_POST] = true; $options[CURLOPT_POSTFIELDS] = array( 'r' => 'request' ); } // check cookie if (in_array('cookie', $this->config['check'])) { $options[CURLOPT_COOKIE] = 'c=cookie'; } // check refderer if (in_array('referer', $this->config['check'])) { $options[CURLOPT_REFERER] = 'http://www.google.com'; } // check user agent if (in_array('user_agent', $this->config['check'])) { $options[CURLOPT_USERAGENT] = 'Mozila/4.0'; } if (!empty($proxyType)) { if ('http' == $proxyType) { $options[CURLOPT_PROXYTYPE] = CURLPROXY_HTTP; } else if ('socks4' == $proxyType) { $options[CURLOPT_PROXYTYPE] = CURLPROXY_SOCKS4; } else if ('socks5' == $proxyType) { $options[CURLOPT_PROXYTYPE] = CURLPROXY_SOCKS5; } } \curl_setopt_array($ch, $options); $content = \curl_exec($ch); $info = \curl_getinfo($ch); return array($content, $info); } private function checkProxyContent($content, $info) { if (!$content) { throw new \Exception('Empty content'); } if (!strpos($content, 'check this string in proxy response content')) { throw new \Exception('Wrong content'); } if (200 !== $info['http_code']) { throw new \Exception('Code invalid: ' . $info['http_code']); } $allowed = array(); $disallowed = array(); foreach ($this->config['check'] as $value) { if (strpos($content, "allow_$value")) { $allowed[] = $value; } else { $disallowed[] = $value; } } // proxy level $proxyLevel = ''; if (strpos($content, 'proxylevel_elite')) { $proxyLevel = 'elite'; } elseif (strpos($content, 'proxylevel_anonymous')) { $proxyLevel = 'anonymous'; } elseif (strpos($content, 'proxylevel_transparent')) { $proxyLevel = 'transparent'; } return array( 'allowed' => $allowed, 'disallowed' => $disallowed, 'proxy_level' => $proxyLevel, 'info' => $info ); } } $pingUrl = 'http://yourdomain.com/ProxyChecker/ping.php'; $proxyChecker = new ProxyChecker($pingUrl); $proxies = array( '183.95.132.76:80', '195.5.18.41:8118', ); $results = $proxyChecker->checkProxies($proxies); echo '<pre>'; var_export($results); echo '</pre';
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/sRtPD:52 Stack trace: #0 /in/sRtPD(43): ProxyChecker\ProxyChecker->getProxyContent('183.95.132.76:8...') #1 /in/sRtPD(32): ProxyChecker\ProxyChecker->checkProxy('183.95.132.76:8...') #2 /in/sRtPD(168): ProxyChecker\ProxyChecker->checkProxies(Array) #3 {main} thrown in /in/sRtPD on line 52
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
Fatal error: Call to undefined function curl_init() in /in/sRtPD on line 52
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/sRtPD on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/sRtPD on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/sRtPD on line 3
Process exited with code 255.

preferences:
224.16 ms | 401 KiB | 315 Q