Russian TYPO3 community Форум больше не используется. Присоединяйтесь к каналу #community-ru в Slack for TYPO3 community  

Вернуться   Russian TYPO3 community > Обсуждение общих технических вопросов > Общие вопросы

 
 
Опции темы Опции просмотра
Старый 19.05.2008, 00:02   #16
Игорь Ф.
Продвинутый
 
Регистрация: 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);

Я прав? Или я что-то не понимаю?
Игорь Ф. вне форума   Ответить с цитированием
 


Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB code is Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.

Быстрый переход

Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Трабл с загрузкой *.t3x в Extension Manager Raven2000 Общие вопросы 6 08.08.2007 18:15
Что за порнографию сделали с Extension Manager в версии 4.1? Guinness Общие вопросы 4 28.03.2007 04:35
Extension Manager не отображается Хороший Общие вопросы 1 16.08.2006 13:29
Extension Manager: nick Установка 1 08.09.2005 11:38
Problem with Extension Manager. Dmi3 Общие вопросы 2 27.04.2005 14:44


Часовой пояс GMT +4, время: 20:21.


Работает на vBulletin® версия 3.8.1.
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Перевод: zCarot

Хостинг и техническая поддержка: TYPO3 Лаборатория