|
Познающий
Регистрация: 26.11.2008
Сообщений: 40
Провел на форуме: 1410006
Репутация:
4
|
|
Дайте советы по увеличению скорости данного скрипта и ошибкам.
Файл index.php
PHP код:
<?php
set_time_limit( 1200 );
include( 'function.inc' );
print date( "H:i:s", time() ) ."<br />"; flush();
$TimeGrab = file ( $TimeGrabProx );
if ( $TimeGrab[0] <= date ( 'd/m/Y H:i:s' , time() ) )
{
print "Обнавляем прокси ... "; flush();
if ( grab ( $proxing, $TimeGrabProx ) !== false )
{
print "Ok!<br />"; flush();
$proxing = file ( 'proxy.txt' );
$count = count ( $proxing );
$display[] = '['.date( "d-m-Y H:i:s", time() ) .']Обновили прокси! '.$count." штук!\r\n";
log_file ( $display, $loger, $display_mess );
unset ( $display );
}
else
{
$display[] = '['.date( "d-m-Y H:i:s", time() ) ."]Ошибка обнавления прокси!\r\n";
log_file ( $display, $loger, $display_mess);
exit();
}
sleep( 10 );
}
$proxing = file ( 'proxy.txt' );
$count = count ( $proxing );
$display[] = "Run friends [".date( "d-m-Y H:i:s", time() ) ."]";
/**********************************************************
/*Заходим в аккаунт
/***********************************************************/
for ($k = 0; $k < count( $acc ); $k++ )
{
if ( $k == 0 )
{
$proxy = $proxing[0];
}
list($nic, $pass, $stst ) = split( ":", $acc[$k] );
$display[] = " << " . $nic .":" .$proxy." >> ";
$data_auth = "?act=login&email=".$nic."&pass=".$pass."&expire=&vk=1";
$delling = false;
if ( $message == 1 ) print "Проверяем <b>" .$nic. "</b> на работоспасобность ...";
do
{
$connect = get_page_html( 'http://vkontakte.ru/login.php', 'http://login.vk.com/', $proxy, $data_auth, 1 );
if ( strstr ( $connect, 'HTTP/1.1 200 OK') !== false xor strstr ( $connect, 'HTTP/1.0 200 OK') !== false )
{
if ( strstr ( $connect, 'HTTP/1.1 302') !== false )
{
//=========================================//
if ( $message == 1 ) print " ok ! <br />"; flush();
preg_match('#\d+#',$connect,$id);
echo $res[0];
//=========================================//
preg_match_all('#Set-cookie: (.*?;) ex#UiS', $connect, $cookie );
if ( !empty( $cookie[1][1] ) )
{
for ( $c = 0; $c < count( $cookie[1] ); $c++)
{
$Cookies .= $cookie[1][$c];
}
if ( strstr ( $Cookies , 'remixsid' ) !== true )
{
$Cookies .= 'remixlang=0;remixchk=5;';
}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
print "Делаем анкету онлайн ..."; flush();
$OnLineOk = false;
do
{
$OnLine = get_page_html( 'http://vkontakte.ru/profile.php', 'http://login.vk.com/?act=login', $proxy, NULL, 1, $Cookies );
if ( strstr ( $OnLine, '/profile.php' ) !== false )
{
//print $OnLine . "<br />"; flush();
print " Ok! <br />"; flush();
$OnLineOk = true;
}
else
{
if ( $proxing[$count-1] == $proxy )
{
print "Идем по списку прокси с начала!<br />\n";
$proxy = reset ( $proxing );
}
else
{
if ( $message == 1 ) print "."; flush();
$proxy = next( $proxing );
}
}
}
while ( !$OnLineOk );
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
//=========================================//
if ( $message == 1 ) print " Смотрим есть ли новые друзья ..."; flush();
$ProfileOk = false;
$fid_count = 0;
do
{
$ProFile = get_page_html( 'http://vkontakte.ru/friends.php?filter=requests', 'http://vkontakte.ru/profile.php', $proxy, NULL, 1, $Cookies );
//print $ProFile; flush();
if ( strstr ( $ProFile, 'http://vkontakte.ru/id1' ) !== false )
{
if ( strstr ( $ProFile, 'Location: /friends.php' ) !== false )
{
print "Заявок нет<br />\n"; flush();
}
else
{
preg_match_all( '#.*\[\[(.*?)\]\],.*#', $ProFile, $FrStr );
preg_match( '#.*\'hash\':\'(.*?)\'.*#', $ProFile, $Hash );
$FrStrExplode = explode( "],[", $FrStr[1][0] );
print " " . count ( $FrStrExplode ) ." в друзья!<br />"; flush();
foreach ( $FrStrExplode as $Fr )
{
preg_match( '#(\d{0,12}),\"(.*?)\",.*#', $Fr, $FrWelId );
print $FrWelId[1]; flush();
$WelcPost = 'fid='.$FrWelId[1].'&act=accept_friend&hash='.$Hash[1].'&cats=1';
/* Приглашаем */
$GoWelk = false;
do
{
$WelkResp = get_page_html( 'http://vkontakte.ru/friends_ajax.php', 'http://vkontakte.ru/friends.php?filter=requests', $proxy, $WelcPost, 1, $Cookies );
if ( strstr ( $WelkResp, 'Заявка принята' ) !== false xor strstr ( $WelkResp, 'Request Accepted' ) !== false xor strstr ( $WelkResp, 'Заявку прийнято' ) !== false)
{
print " Ok <br />\n"; flush();
$GoWelk = true;
}
else
{
if ( $proxing[$count-1] == $proxy )
{
print "Идем по списку прокси с начала!<br />\n";
$proxy = reset ( $proxing );
}
else
{
if ( $message == 1 ) print "."; flush();
$proxy = next( $proxing );
}
}
}
while ( !$GoWelk );
/* */
}
}
$ProfileOk = true;
}
else
{
if ( $proxing[$count-1] == $proxy )
{
print "Идем по списку прокси с начала!<br />\n";
$proxy = reset ( $proxing );
}
else
{
if ( $message == 1 ) print "."; flush();
$proxy = next( $proxing );
}
}
}
while ( !$ProfileOk );
$display[] = "[ " . count ( $FrStrExplode ) . " ] new friends - is accepted ! ";
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
$delling = true;
}
else
{
if ( $proxing[$count-1] == $proxy )
{
print "Идем по списку прокси с начала!<br />\n";
$proxy = reset ( $proxing );
}
else
{
if ( $message == 1 ) print "."; flush();
$proxy = next( $proxing );
}
}
/////////////////////////////////////////////
}
elseif ( strstr ( $connect, 'failed') !== false )
{
if ( $message == 1 ) print " Удален ! <br />"; flush();
$DellAcc = fopen ( $DelLog, 'a+' );
if ( $DellAcc )
{
$RecordDellAcc = "[ ".date( "d-m-Y H:i:s", time() ). " ] " . $nic . " Сайт ответил: анкета удалена.\n";
fputs( $DellAcc, $RecordDellAcc );
}
else
{
if ( $message == 1 ) print "Не смогли записать в файл удаленную анкету<br />";
flush();
}
fclose( $DellAcc );
$delling = true;
}
elseif ( strstr ( $connect, 'Enter code') !== false )
{
if ( $message == 1 ) print " требует ввода капчии, спим 30 сек ...<br />"; flush();
if ( $proxing[$count-1] == $proxy )
{
print "Идем по списку прокси с начала!<br />\n";
$proxy = reset ( $proxing );
}
else
{
$proxy = next( $proxing );
}
sleep( 30 );
if ( $message == 1 ) print " пробуем снова ..."; flush();
}
else
{
if ( $proxing[$count-1] == $proxy )
{
print "Идем по списку прокси с начала!<br />\n";
$proxy = reset ( $proxing );
}
else
{
if ( $message == 1 ) print "."; flush();
$proxy = next( $proxing );
}
}
}
else
{
if ( $proxing[$count-1] == $proxy )
{
print "Идем по списку прокси с начала!<br />\n";
$proxy = reset ( $proxing );
}
else
{
if ( $message == 1 ) print "."; flush();
$proxy = next( $proxing );
}
}
}
while ( !$delling );
$Cookies = '';
sleep( 5 );
}
$display[] = $k . " vsego onlain акаунта(ов) [".date( "d-m-Y H:i:s", time() ) ."]\r\n";
print date("H:i:s", time()) . "<br />"; flush();
if ( $message == 1 )
{
print log_file ( $display, $loger, $display_mess );
}
?>
Файл function.inc
PHP код:
<?php
date_default_timezone_set( 'Europe/Kiev' );
$display = array(); //Массив с сообщениями
$loger = 1; // 1 Включает зпись логов, 0 выключает;
$display_mess = 0; // 1 Включает вывод сообщения о прделоной работе, 0 выключает;
$message = 1;// 1 Включает вывод сообщения о ходе работы, 0 выключает;
// Файл счетчик обновления прокси
if ( file_exists( 'count_prox.dat' ) )
{
$TimeGrabProx = 'count_prox.dat';
}
else
{
$CreaetTimeGrabProx = fopen( 'count_prox.dat', 'w+' );
if ( $CreaetTimeGrabProx )
{
chmod( 'count_prox.dat', 0666 );
print "Создали файл 'count_prox.dat' <br />"; flush();
}
fclose ( $CreaetTimeGrabProx );
$TimeGrabProx = 'count_prox.dat';
}
// Файл удаленных анкет
if ( file_exists( 'DellAcc.txt' ) )
{
$DelLog = 'DellAcc.txt';
}
else
{
$CreaetDelLog = fopen( 'DellAcc.txt', 'w+' );
if ( $CreaetDelLog )
{
chmod( 'DellAcc.txt', 0666 );
print "Создали файл 'DellAcc.txt' <br />"; flush();
}
fclose ( $CreaetDelLog );
$DelLog = 'DellAcc.txt';
}
if ( file_exists( 'proxy.txt' ) )
{
$proxing = file ( 'proxy.txt' ); // Файл с прокси
}
else
{
exit ( 'Нет файла прокси!');
}
///////////
if ( file_exists( 'acc.inc' ) )
{
$acc = file ( 'acc.inc' ); // Файл с анкетами
}
else
{
exit ( 'Нет файла с аккаунтами!');
}
function count_prox ( $TimeGrabProx, $Time=7200 )
{
$acc_rec = fopen ( $TimeGrabProx, "w+" );
if ( flock( $acc_rec, LOCK_EX ) )
{
fseek($acc_rec, 0 );
fputs( $acc_rec, date ( "d/m/Y H:i:s", ( time () + $Time ) ) );
flock( $acc_rec, LOCK_UN);
}
fclose ($acc_rec);
}
function log_file ( $var, $stat, $display_mess ) // Функция для ведения лог файла
{
if ( $stat == 1 )
{
if ( file_exists( 'log_file.txt' ) )
{
$log_file = fopen ( 'log_file.txt', "a+" ) or die( "Не могу открыть log_file.txt" );
}
else
{
$log_file = fopen ( 'log_file.txt', "a+" ) or die( "Не могу открыть log_file.txt" );
if ( $log_file )
{
chmod( 'log_file.txt', 0666 );
}
}
if ( flock( $log_file, LOCK_EX ) )
{
rewind ( $log_file );
fputs( $log_file, @implode( " ", $var ) );
flock( $log_file, LOCK_UN);
}
else
{
return "Не могу запереть файл";
}
fclose ( $log_file );
}
if ( $display_mess == 1 )
{
$del = array_shift ( $var );
$del = array_pop ( $var );
return @implode ( " ", $var ) . flush();
}
}
function get_page_html( $url, $Refer='', $proxy='', $post='', $num='', $Cookie='' )
{
$agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
$curltop = curl_init();
if ( !empty ( $proxy ) )
{
curl_setopt( $curltop, CURLOPT_PROXY, $proxy );
}
curl_setopt( $curltop, CURLOPT_URL, $url );
if ( !empty( $Refer ) )
{
curl_setopt( $curltop, CURLOPT_REFERER, $Refer );
}
curl_setopt( $curltop, CURLOPT_USERAGENT, $agent );
curl_setopt( $curltop, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curltop, CURLOPT_FOLLOWLOCATION, 1 );
if ( empty( $Cookie ) )
{
$cookiefile = 'cookie.inc';
if ( !file_exists( $cookiefile ) )
{
$handle = fopen( $cookiefile, 'w' );
chmod( 'cookie.inc', 0666 );
fclose( $handle );
}
curl_setopt( $curltop, CURLOPT_COOKIEFILE, $cookiefile );
curl_setopt( $curltop, CURLOPT_COOKIEJAR, $cookiefile );
}
else
{
curl_setopt( $curltop, CURLOPT_COOKIE, $Cookie );
}
curl_setopt( $curltop, CURLOPT_TIMEOUT, 15 );
if ( $num == 1 )
{
curl_setopt( $curltop, CURLOPT_HEADER, 1 );
}
if ( !empty( $post ) )
{
curl_setopt( $curltop, CURLOPT_POST, 1 );
curl_setopt( $curltop, CURLOPT_POSTFIELDS, $post );
}
$html = curl_exec( $curltop );
//echo $html;
curl_close ( $curltop );
return !empty( $html ) ? $html : false;
}
function grab ( $proxing, $TimeGrabProx )
{
$FileRezer = file ( 'proxy.txt' );
$file_prox = fopen ( 'proxy.txt', 'w+' );
flock( $file_prox, LOCK_EX );
$ArrayLinc[] = 'http://freeproxylist.org/en/free-proxy-list.htm';
for ( $p = 1; $p <= 50; $p ++ )
{
$ArrayLinc[$p] = 'http://freeproxylist.org/en/free-proxy-list.htm?index='.$p ;
}
foreach ( $ArrayLinc as $key => $Linc )
{
if ( $key == 0 )
{
$PostSend = 'cc=any&ssl=any&speed=0&port=any&connect=any&ping=15.0000&type=any&post=any&uptime=0§ion=both&codeen=any&interval=360&userip=94.178.217.103&code=AW1VfWYjMueusyuh&filter=save+and+apply+filter+options';
}
else
{
$PostSend = null;
}
$Prox = get_page_html ( Null, $Linc, Null, Null, $PostSend, 0 );
if ( !empty( $Prox ) )
{
preg_match_all( "/(\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3}:\d{0,6})/", $Prox, $ProxSort );
if ( !empty ( $ProxSort[1][0] ) )
{
//print $Linc ." Ok!<br />"; flush();
for ( $i = 0; $i < count ( $ProxSort[1] ); $i ++ )
{
fwrite( $file_prox, $ProxSort[1][$i]."\n" );
}
$prox_url_ok = true;
}
}
else
{
if ( ( $p - 1 ) == $key )
{
if ( filesize( 'proxy.txt' ) <= 10 )
{
fwrite( $file_prox, @implode( "", $FileRezer ) );
$prox_url_ok = false;
}
}
}
}
flock( $file_prox, LOCK_UN);
fclose( $file_prox );
count_prox ( $TimeGrabProx );
return $prox_url_ok;
}
?>
|