Не создаёт файл больше 100кб

12
R
На сайте с 19.07.2010
Offline
64
1381

Всем привет.

У меня вот такая беда, парсер вытаскивает результаты матчей со спортивного сайта. Всё работает вроде бы нормально, результат записывается в файл, но файл больше 100кб не создается.

В php.ini

post_max_size = 30M

upload_max_filesize = 30M

nginx.conf

client_max_body_size 10m;

client_body_buffer_size 128k;

proxy_buffer_size 4k;

proxy_busy_buffers_size 64k;

proxy_temp_file_write_size 64k;

то-есть вроде-бы всё ок.

вот сама функция

function get_web_page( $url, $bot )

{

$uagent = array(
"Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)",
"Mozilla/5.0 (compatible; Mail.RU/2.0)",
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
"Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)",
"Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0"
);

$ch = curl_init( $url );

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_USERAGENT, $uagent[$bot]);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_MAXREDIRS, 50);

$content = curl_exec( $ch );
curl_close( $ch );
return $content;
}

Ребята может кто подскажет, что за байда, как разрешить создание файлов более 100кб. я уже всю голову себе сломал блин.

Сейчас его пилю http://newsrbk.ru/ (http://newsrbk.ru/)
siv1987
На сайте с 02.04.2009
Offline
427
#1

здесь ничего не сказано о том, каким образом вы сохраняете файл.

forest25
На сайте с 12.09.2009
Offline
67
#2

ТС, и для чего вы выложили кусок файла с функциями инициализации curl? Конкретно к вашему вопросу это никакого отношения не имеет.

Для начала:

1) Включите error_log в PHP

2) Найдите функцию отвечающую за сохранение файла и дебажьте ее. Если нет возожности это делать нормальным дебаггером, то хотя бы смотрите что там творится путем вывода диагностических сообщений с содержимым переменных.

VPS 512MB 20GB SSD KVM - 5$ (http://u.hmdw.me/digitalocean) | ИМХО о хостингах (http://u.hmdw.me/hosting)
masterfunk
На сайте с 05.11.2007
Offline
104
#3

Еще может не в переменную писать, а сразу в файл.

R
На сайте с 19.07.2010
Offline
64
#4

вот класс, создание кеш


<?php

if( ! class_exists( 'NEWSRBK_API' ) )
{
class NEWSRBK_API
{
var $result = false;
var $cache_dir = false;
var $cache_files = array();

function NEWSRBK_API()
{
if (!$this->cache_dir)
{
$this->cache_dir = $_SERVER['DOCUMENT_ROOT']."/cache/service/";
}
return true;
}

function save_to_cache ($fname, $vars)
{
$filename = $fname.".tmp";
$f = @fopen($this->cache_dir.$filename, "w+");
@chmod('0777', $this->cache_dir.$filename);
if (is_array($vars)) $vars = serialize($vars);
@fwrite($f, $vars);
@fclose($f);
return $vars;
}

function load_from_cache ($fname, $timeout=300, $type = 'text')
{
$filename = $fname.".tmp";
if (!file_exists($this->cache_dir.$filename)) return false;
if ((filemtime($this->cache_dir.$filename)) < (time()-$timeout)) return false;

if ($type=='text')
{
return file_get_contents($this->cache_dir.$filename);
}
else
{
return unserialize(file_get_contents($this->cache_dir.$filename));
}
}

function clean_cache($name = "GLOBAL")
{
$this->get_cached_files();

if ($name=="GLOBAL")
{
foreach ($this->cache_files as $cached_file)
{
@unlink($this->cache_dir.$cached_file);
}
}
elseif (in_array($name.".tmp", $this->cache_files))
{
@unlink($this->cache_dir.$name.".tmp");
}
}

function get_cached_files()
{
$handle = opendir($this->cache_dir);
while (($file = readdir($handle)) !== false)
{
if ($file != '.' && $file != '..' && (!is_dir($this->cache_dir.$file) && $file !='.htaccess'))
{
$this->cache_files [] = $file;
}
}
closedir($handle);
}

}
}

$newsrbk_api = new NEWSRBK_API ();
if( ! isset( $result ) ) {
include_once ($_SERVER['DOCUMENT_ROOT'].'/includes/config.php');

}
$newsrbk_api->result = $result;
?>
SocFishing
На сайте с 26.09.2013
Offline
118
#5

function get_web_page( $url, $bot )
{

$uagent = array(
"Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)",
"Mozilla/5.0 (compatible; Mail.RU/2.0)",
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
"Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)",
"Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0"
);

$ch = curl_init( $url );

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_USERAGENT, $uagent***91;$bot***93;);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_MAXREDIRS, 50);

$content = curl_exec( $ch );
file_put_contents("mycontent.txt", $content, FILE_APPEND | LOCK_EX);

curl_close( $ch );
return $content;
}

Вы не написали, как вы используете функцию get_web_page и какой функцией идет запись.

здесь ничего не сказано о том, каким образом вы сохраняете файл.

задавал вопрос.

★Сервис идентифицирует (https://socfishing.com/?utm_source=searchengines) посетителей вашего сайта и предоставляет их профили ВКонтакте, Телефон, Почта! Цены копеечные, работаем 8 лет.
R
На сайте с 19.07.2010
Offline
64
#6

вот весь код

<?php

define ( 'NEWSRBKHACKING', true );

@ini_set( 'display_errors', true );
@ini_set( 'html_errors', false );

@ini_set( '2048M' );
@ini_set( 'memory_limit', '128M' );
@ini_set( 'max_execution_time', 0 );
@ini_set( 'output_buffering', 'off' );

include($_SERVER['DOCUMENT_ROOT'].'/includes/template.php');
include($_SERVER['DOCUMENT_ROOT'].'/includes/lang/russian.php');
include($_SERVER['DOCUMENT_ROOT'].'/includes/class_api.php');

$searchsports_2=$newsrbk_api->load_from_cache( "searchsports_2_$number", 6);
if (!$searchsports_2) {

function get_web_page( $url, $bot )
{
$uagent = array(
"Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)",
"Mozilla/5.0 (compatible; Mail.RU/2.0)",
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
"Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)",
"Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0"
);

$ch = curl_init( $url );

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_USERAGENT, $uagent[$bot]);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_MAXREDIRS, 50);

$content = curl_exec( $ch );
curl_close( $ch );
return $content;
}

$content=get_web_page("http://newsrbk.ru/sport/45.html");

preg_match_all ('#<table align="center" width="90%">(.*?)<script language="JavaScript">#si', $content, $content);

for($i=0; $i < count($content[1]); $i++)
{
$name = $content[1][$i];
}

$searchsports_2 .= '<table align="center" width="100%">'.$name.'';

$newsrbk_api->save_to_cache ( "searchsports_2_$number", $searchsports_2);
}

$content = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/tpl/news/allsports.tpl');
$content = str_replace('{TITLE}',$page_title,$content);
$content = str_replace('{SEARCHSPORTS}',$searchsports_2,$content);

echo ApplyTemplate($_SERVER['DOCUMENT_ROOT'].'/tpl/main_allsports.php', Array('content'=>$content, 'page_title'=>$page_title, 'page_keywords'=>$page_keywords, 'page_description'=>$page_description));

?>

ссылка, что пытаюсь распарсить http://newsrbk.ru/sport/45.html

а сам класс я добавил чуть выше

SocFishing
На сайте с 26.09.2013
Offline
118
#7

Если попробовать

@ini_set( 'memory_limit', '256M' );

тут я не совсем понял, что выполняется в цикле, какова цель передачи в цикле в $name.

for($i=0; $i < count($content***91;1***93;); $i++)
{
$name = $content***91;1***93;***91;$i***93;;
}

$searchsports_2 .= '<table align="center" width="100%">'.$name.'';

рекомендация такая. выводить var_dump по всему ходу выполнений. так поймете где именно у вас урезает? или не все пишет в файл.

или пишите переменные через

file_put_contents("mycontent".rand().".txt", $content, FILE_APPEND | LOCK_EX);
для массивов serialize($content)
R
На сайте с 19.07.2010
Offline
64
#8

это @ini_set( 'memory_limit', '256M' ); не помогает, уже пробовал.

а что здесь не понятно?


preg_match_all ('#<table align="center" width="90%">(.*?)<script language="JavaScript">#si', $contentout, $content);

for($i=0; $i < count($content[1]); $i++)
{
$name = $content[1][$i];
}

$searchsports_2 .= '<table align="center" width="100%">'.$name.'';

$searchsports_2 = данные записываемые в файл, у меня там кеширование, создаётся файл и потом читаем из него

вот $newsrbk_api->save_to_cache ( "searchsports_2", $searchsports_2); данные переменной $searchsports_2 записываем в файл searchsports_2.tmp

SocFishing
На сайте с 26.09.2013
Offline
118
#9

$name тогда зачем в цикле вызывается,

$name = $content***91;1***93;***91;$i***93;;

такое чувство что со скобками } еще мудрежка,

$searchsports_2 .=

хотя он по коду исполняется 1 раз.

может все же так

for($i=0; $i < count($content***91;1***93;); $i++)
{
$name = $content***91;1***93;***91;$i***93;;
$searchsports_2 .= '<table align="center" width="100%">'.$name.'';
}

R
На сайте с 19.07.2010
Offline
64
#10

SocFishing не, таже байда, та сам парсер парсит нормально вот можно посмотреть его работу http://newsrbk.ru/sport/ в левом сайтбаре выберите раздел хоккей http://newsrbk.ru/allsports/2/ всё ок, потом раздел футбол http://newsrbk.ru/allsports/1/ в нём больше входных данных и файл кеша вообще не создаётся.

просто напросто файл до 100кб создаётся нормально, а вот больше чем 100кб не создаётся, я сам не могу понять что е так

12

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий