Керл не успевает отработать при запуске через Cron

У меня есть PHP cron-скрипт

Class Cron {
public function __construct {
$this->dosomething();
}
private function dosomething () {
$curl = app_curl();
}
}

function app_curl () {
... $ Curl ...
return $ curl;
}

Когда я запускаю этот скрипт — он не устраивает и прерывает Cron. Если я запускаю отдельно app_curl (), то все работает правильно.

// полный код

// Cli / Auto Cron файл (воспламенитель кода)

class Auto extends CLI_Controller {
public function index() {
$this->process_broadcasts();
} // function

private function process_broadcasts(){
$curl = app_curl_get_postmaster();
} // function
} // class

// curl_function

function get_web_page($url, $post = array())
{
if (!isset($url) || empty($url)) return false;
$uagent = "Opera/9.80 (Windows NT 6.1; WOW64) Presto/2.12.388 Version/12.14";

$ch = curl_init( $url );

$path = dirname(__FILE__);
$tmpfile = $path . DIRECTORY_SEPARATOR . 'cookie' . '.txt';

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);     // возвращает веб-страницу

curl_setopt($ch, CURLOPT_HEADER, 0);             // не возвращает заголовки
curl_setopt($ch, CURLOPT_ENCODING, "");          // обрабатывает все кодировки
curl_setopt($ch, CURLOPT_USERAGENT, $uagent);    // useragent

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);   // таймаут соединения
curl_setopt($ch, CURLOPT_TIMEOUT, 120);          // таймаут ответа

curl_setopt($ch, CURLOPT_COOKIESESSION, 1);     // переходит по редиректам
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);     // переходит по редиректам
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);         // останавливаться после 10-ого редиректа

curl_setopt($ch, CURLOPT_COOKIEFILE,  $tmpfile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfile);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

if (isset($post) && !empty($post)) {
if (!is_array($post)) $post[$$post] = $post;
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
}

$content = curl_exec( $ch );
$err     = curl_errno( $ch );
$errmsg  = curl_error( $ch );
$header  = curl_getinfo( $ch );
curl_close( $ch );

$header['errno']   = $err;
$header['errmsg']  = $errmsg;
$header['content'] = $content;
return $header;
}

// get_postmaster

function app_curl_get_postmaster($date = null) {
if ($date === null) $date = date('d.m');

$post = array(
'Login' => 'gzhegow2@mail.ru',
'Domain' => 'mail.ru',
'Password' => '321qwe',
'saveauth' => 1,
'new_auth_form' => 1,
'page' => 'https://postmaster.mail.ru/',
'post' => '',
'login_form' => ''
);

$v = get_web_page('https://auth.mail.ru/cgi-bin/auth', $post);
$v = get_web_page('https://postmaster.mail.ru/100tr.ru/');

$html = str_get_html($v['content']);

$tmp = array();
$arr = array();

$tr_counter = 0;
foreach ($html->find('table[id=stats] tr') as $tr) {
foreach ($tr->find('td[class*=statistic-table__date]') as $td) {
$tmp[$tr_counter]['date'] = trim($td->plaintext);
}
foreach ($tr->find('td[class*=statusbar__delivered]') as $td) {
$tmp[$tr_counter]['good'] = trim($td->plaintext);
}
foreach ($tr->find('td[class*=statusbar__probspam]') as $td) {
$tmp[$tr_counter]['warn'] = trim($td->plaintext);
}
foreach ($tr->find('td[class*=statusbar__spam]') as $td) {
$tmp[$tr_counter]['spam'] = trim($td->plaintext);
}
$tr_counter++;
};

foreach ($tmp as $item) {
if (isset($item['date']) && !empty($item['date'])) $arr[$item['date']] = $item;
}

return $arr[$date];
}

Я думаю, что у Curl нет времени на выполнение, когда он запускается через другой скрипт, но если я делаю

print_r(app_curl_get_postmaster());

тогда все работает нормально. Что может быть причиной?

0

Решение

Lol, я использую ::

error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('max_execution_time', 3600);
ini_set('memory_limit', '256M');

мне говорят, что «str_get_html» — это «неизвестная функция».
Я действительно требует simple_html_dom.php, и это работает.

Спасибо всем, ребята, за помощь!

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector