Bonjour à tous !
j'ai un probleme de base de données avec ce script
MySql me retourne presque à chaque fois "
Error : MySQL server has gone away "
pour résumer le script :
il charge une page web du site p0rnhub
puis il cherche les identifiants des vidéos qui sont sur la page
il cherche ensuite les images associées aux vidéos
( jusque là tout fonctionne très bien )
puis pour l'enregisrement dans la bdd il m'affiche "server has gone away "
quelqu'un à une idée ??
<?php
//session_start( );
include( "include/config.php" );
include( "include/functions/import.php" );
$thebaseurl = $config['baseurl'];
if ($_SESSION[USERID] != "" && $_SESSION[USERID] >= 0 && is_numeric($_SESSION[USERID]))
{
function download_file( $file_source, $file_target )
{
//if ( file_exists( $file_target ) )
//{
// echo "<br>file exist";
// return false;
//}
$rh = fopen( $file_source, "rb" );
$wh = fopen( $file_target, "wb" );
if ( $rh === false || $wh === false )
{
return false;
}
while ( !feof( $rh ) )
{
if ( fwrite( $wh, fread( $rh, 1024 ) ) === FALSE )
{
return false;
}
}
fclose( $rh );
fclose( $wh );
//echo "<br>everything went ok ";
return true;
}
function download_my_remote_thumbs( $thumb_url, $video_id )
{
global $config;
//download the first thumbnail image
download_file( $thumb_url.".jpg", $config['thumbdir']."/".$video_id."-1.jpg" );
//make also a copy
download_file( $config['thumbdir']."/".$video_id."-1.jpg", $config['thumbdir']."/".$video_id."-2.jpg" );
download_file( $config['thumbdir']."/".$video_id."-1.jpg", $config['thumbdir']."/".$video_id."-3.jpg" );
download_file( $config['thumbdir']."/".$video_id."-1.jpg", $config['thumbdir']."/".$video_id."-4.jpg" );
download_file( $config['thumbdir']."/".$video_id."-1.jpg", $config['thumbdir']."/".$video_id."-5.jpg" );
download_file( $config['thumbdir']."/".$video_id."-1.jpg", $config['thumbdir']."/".$video_id."-6.jpg" );
download_file( $config['thumbdir']."/".$video_id."-1.jpg", $config['thumbdir']."/".$video_id."-7.jpg" );
download_file( $config['thumbdir']."/".$video_id."-1.jpg", $config['thumbdir']."/".$video_id."-8.jpg" );
download_file( $config['thumbdir']."/".$video_id."-1.jpg", $config['thumbdir']."/".$video_id."-9.jpg" );
download_file( $config['thumbdir']."/".$video_id."-1.jpg", $config['thumbdir']."/".$video_id."-10.jpg" );
return true;
}
if ( isset( $_REQUEST['submit'] ) )
{
$keyword = $_REQUEST['keyword'];
$amount = intval( $_REQUEST['amount'] );
$category = intval( $_POST['category'] );
if ( $keyword == "" )
{
$error = $langph['6']; // msg : " Please enter a keyword to search for.";
}
else if ( $category <= "0" )
{
$error = $lang['462']; //msg : " Please select a category.";
}
$videosperpage = "24";
if ( !$error )
{
if ( $amount == "0" )
{
$amount = 1;
}
$page = 1;
$validcount = 0;
$addedvids = 0;
while ( $validcount < $amount )
{
$html = file_get_contents( "http://www.pornhub.com/video/search?search=".$keyword."&page=".$page );
preg_match_all( "/Broaden your(.+?)search/", $html, $nomatch );
$noresult = array_unique( $nomatch );
$rcount = count( $noresult[0] );
$rmsg = $noresult[0][0];
if ( 0 < $rcount )
{
$validcount = $amount;
$rskip = "1";
}
if ( $rskip != "1" )
{
preg_match_all( "/<a href = \"http:\\/\\/www.pornhub.com\\/view_video.php\\?viewkey=(.+?)\"/", $html, $match );
$result1 = array_unique( $match );
$count = count( $result1[0] );
preg_match_all( "/<div class=\"box-left\">(.+?)</", $html, $match5 );
$result5 = array_unique( $match5 );
preg_match_all( "/<img src=\"http:\\/\\/p1\\.pornhub\\.com\\/thumbs\\/000\\/(.+?)alt=/", $html, $match3 );
$result3 = array_unique( $match3 );
$count = count( $result3[0] );
$i = 0;
foreach ( $result1 as $val )
{
foreach ( $val as $item )
{
if ( $validcount < $amount )
{
$item = str_replace( "<a href = \"http://www.pornhub.com/view_video.php?viewkey=", "", $item );
$item = str_replace( "\"", "", $item );
if ( $item != "" )
{
$query = "SELECT count(*) as total FROM videos WHERE pornhub='".mysql_real_escape_string( $item )."'";
$executequery = $conn->execute( $query );
$pornhubtotal = $executequery->fields[total] + 0;
if ( $pornhubtotal == "0" )
{
$validcount++;
$contin = "1";
$titleandthumb = $result3[0][$i];
preg_match_all( "/src=\"(.+?)\\.jpg/", $titleandthumb, $match6 );
$result6 = array_unique( $match6 );
$thumb = $result6[0][0];
$thumb = str_replace( "src=\"", "", $thumb );
$thumb = substr( $thumb, 0, 0 - 4 );
$hubid = $thumb;
$hubid = str_replace( "small", "", $hubid );
$hubid = str_replace( "/", "", $hubid );
$hubid = substr( $hubid, 0 - 6 );
$hubid = intval( $hubid );
preg_match_all( "/title=\"(.+?)\"/", $titleandthumb, $match7 );
$result7 = array_unique( $match7 );
$title = $result7[0][0];
$title = str_replace( "title=\"", "", $title );
$title = str_replace( "\"", "", $title );
$rtime = $result5[0][$i];
$rtime = str_replace( "<div class=\"box-left\">", "", $rtime );
$rtime = str_replace( "<", "", $rtime );
$pos = strrpos( $rtime, ":" );
$mins = substr( $rtime, 0, $pos );
$mins = intval( $mins );
$secs = substr( $rtime, 0 - 2 );
$secs = intval( $secs );
$trtime = $mins * 60 + $secs;
$approve_videos = $config[approve_videos];
if ( $approve_videos == 1 )
{
$active = "active='0'";
}
else
{
$active = "active='1'";
}
$title = stripslashes( ereg_replace( "\"", """, $title ) );
$thetitle = htmlentities( strip_tags( $title ), ENT_QUOTES, "UTF-8" );
$thetags = htmlentities( strip_tags( $title ), ENT_QUOTES, "UTF-8" );
$thedesc = htmlentities( strip_tags( $title ), ENT_QUOTES, "UTF-8" );
$thecat = htmlentities( strip_tags( $_POST[category] ), ENT_QUOTES, "UTF-8" );
$thepublic = intval( $_POST['public'] );
$thepublic = htmlentities( strip_tags( $thepublic ), ENT_QUOTES, "UTF-8" );
$theallowcomments = intval( $_POST['allowcomments'] );
$theallowcomments = htmlentities( strip_tags( $theallowcomments ), ENT_QUOTES, "UTF-8" );
$theallowratings = intval( $_POST['allowratings'] );
$theallowratings = htmlentities( strip_tags( $theallowratings ), ENT_QUOTES, "UTF-8" );
$theallowembeds = intval( $_POST['allowembeds'] );
$theallowembeds = htmlentities( strip_tags( $theallowembeds ), ENT_QUOTES, "UTF-8" );
$theallowdownloads = intval( $_POST['allowdownloads'] );
$theallowdownloads = htmlentities( strip_tags( $theallowdownloads ), ENT_QUOTES, "UTF-8" );
$themature = intval( $_POST['mature'] );
$themature = htmlentities( strip_tags( $themature ), ENT_QUOTES, "UTF-8" );
$query = "INSERT INTO videos SET USERID='{$_SESSION['USERID']}', title='".mysql_real_escape_string( $thetitle )."', description='".mysql_real_escape_string( $thedesc )."', tags='".mysql_real_escape_string( $thetags )."', categories='".mysql_real_escape_string( $thecat )."', filesize='10', public='".mysql_real_escape_string( $thepublic )."', time_added='".time( )."', date_added='".date( "Y-m-d" )."', {$active}, allowcomments='".mysql_real_escape_string( $theallowcomments )."', allowratings='".mysql_real_escape_string( $theallowratings )."', allowembeds='".mysql_real_escape_string( $theallowembeds )."', allowdownloads='".mysql_real_escape_string( $theallowdownloads )."', pornhub='".mysql_real_escape_string( $item )."', pornhub2='".mysql_real_escape_string( $hubid )."', runtime='".mysql_real_escape_string( $trtime )."', mature='".mysql_real_escape_string( $themature )."'";
$conn->execute( $query ) or die(mysql_error()) ;
//script crash here : " Error : MySQL server has gone away "
$videoid = mysql_insert_id( );
if ( is_numeric( $videoid ) && 0 < $videoid )
{
download_my_remote_thumbs( $thumb, $videoid );
$addedvids++;
}
}
}
}
$i++;
}
}
$page++;
}
}
}
}
}
stemplate::assign( "pagetitle", $langph['1'] );
stemplate::assign( "error", $error );
stemplate::display( "header.tpl" );
stemplate::display( "pornhub.tpl" );
stemplate::display( "footer.tpl" );
?>
Don't Hate The Hacker, Hate The Code