Продвинутый
Регистрация: 16.05.2008
Сообщений: 68
|
Цитата:
Сообщение от void
Она работает через CURL только если вы прямо задали такую настройку в Install Tool. В других случаях она работает через fsockopen.
|
Ну, вот как выглядит функция, которая мне возвращает 0 вместо какого-то значения:
Цитата:
function getURL($url, $includeHeader = 0, $requestHeaders = false) {
$content = false;
// (Proxy support implemented by Arco <arco@appeltaart.mine.nu>)
if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse'] == '1' && preg_match('/^https?:\/\//', $url)) {
// External URL without error checking.
$ch = curl_init();
if (!$ch) {
return false;
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, $includeHeader ? 1 : 0);
curl_setopt($ch, CURLOPT_NOBODY, $includeHeader == 2 ? 1 : 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
if (is_array($requestHeaders)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $requestHeaders);
}
// may fail (5.2.0, 5.1.5+ and 4.4.4+) when open_basedir or safe_mode are enabled
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']) {
curl_setopt($ch, CURLOPT_PROXY, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']);
// Not sure if this is needed
if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyTunnel']) {
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyTunnel']);
}
if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass']) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass']);
}
}
$content = curl_exec($ch);
curl_close($ch);
} elseif ($includeHeader) {
$parsedURL = parse_url($url);
if (!t3lib_div::inList('http,https', $parsedURL['scheme'])) {
return false;
}
$port = intval($parsedURL['port']);
if ($parsedURL['scheme'] == 'http') {
$port = ($port>0 ? $port : 80);
$scheme = '';
} else {
$port = ($port>0 ? $port : 443);
$scheme = 'ssl://';
}
$fp = @fsockopen($scheme.$parsedURL['host'], $port, $errno, $errstr, 2.0);
if (!$fp || $errno > 0) {
return false;
}
$msg = 'GET ' . $parsedURL['path'] .
($parsedURL['query'] ? '?' . $parsedURL['query'] : '') .
' HTTP/1.0' . "\r\n" . 'Host: ' .
$parsedURL['host'] . "\r\n";
if (is_array($requestHeaders)) {
$msg .= implode("\r\n", $requestHeaders). "\r\n";
}
$msg .= "\r\n";
fputs($fp, $msg);
while (!feof($fp)) {
$line = @fgets($fp, 2048);
$content.= $line;
if ($includeHeader == 2 && !strlen(trim($line))) {
break; // Stop at the first empty line (= end of header)
}
}
fclose($fp);
} elseif (is_array($requestHeaders)) {
$ctx = stream_context_create(array(
'http' => array(
'header' => implode("\r\n", $requestHeaders)
)
)
);
if (version_compare(phpversion(), '5.0', '>=')) {
$content = @file_get_contents($url, false, $ctx);
}
elseif (false !== ($fd = @fopen($url, 'rb', false, $ctx))) {
$content = '';
while (!feof($fd)) {
$content.= @fread($fd, 4096);
}
fclose($fd);
}
}
else {
$content = @file_get_contents($url);
}
return $content;
}
|
Так как у меня переменная только одна, то соотвтетственно я на второй и третий elseif вообще не смотрю.
То есть остается только:
Цитата:
function getURL($url, $includeHeader = 0, $requestHeaders = false) {
$content = false;
// (Proxy support implemented by Arco <arco@appeltaart.mine.nu>)
if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse'] == '1' && preg_match('/^https?:\/\//', $url)) {
// External URL without error checking.
$ch = curl_init();
if (!$ch) {
return false;
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, $includeHeader ? 1 : 0);
curl_setopt($ch, CURLOPT_NOBODY, $includeHeader == 2 ? 1 : 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
if (is_array($requestHeaders)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $requestHeaders);
}
// may fail (5.2.0, 5.1.5+ and 4.4.4+) when open_basedir or safe_mode are enabled
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']) {
curl_setopt($ch, CURLOPT_PROXY, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']);
// Not sure if this is needed
if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyTunnel']) {
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyTunnel']);
}
if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass']) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass']);
}
}
$content = curl_exec($ch);
curl_close($ch);
...
else {
$content = @file_get_contents($url);
}
return $content;
}
|
Получается, что если CURL включен, то выполняется первая процедура, а если нет, то все сводится к строчке:
$content = @file_get_contents($url);
Я прав? Или я что-то не понимаю?
|