Hey I have a program I wrote here, http://dnfinder.net/rentacoder/test...ves/company/0/companies.html&option=startover I'll put the code below and won't change it, I have a callback function that is required because when I am doing massive searches with the CURL_Multi interface it won't stop until it finishes and the only way to stop it is to perform a killcheck() while it's doing it's operations. It just checks to see if a file exists like kill.txt. So if I can get a callback function working I can make the program stop execution, please help =), will pay for assistance. Currently I can get CURLOPT_WRITEFUNCTION to display the data coming in, but then it causes errors somehow in my code down the line, where just by taking out the callback function my program works fine. Which tells me it's not my code that is bad but something I did in the callback function perhaps? something I'm not understanding? Your help is much appreciated! Code below! <?php //Functions--------------------------------------------------------------------------------------------------------------------------------------- //Utility Functions ############################################################################################################################## function set_timeout_time($time) { if($time<>0) { set_time_limit($time); } else { //ToDo: Put the time limit back to normal [800] set_time_limit(60);//so your server doesn't burn and crash and die, but will still go a while. //ignore_user_abort(true);//so the user can't disconnect and stop the script, whole reason I'm re-scripting is because of this. } echo '<br>Time Limit:'.ini_get('max_execution_time'); } function getResultsFromURLArray($urls) { $mh = curl_multi_init(); foreach ($urls as $i => $url) { $conn[$i]=curl_init($url); $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,"; $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; if($_GET['javascript']==1) { $header[] = "content-type: application/x-javascript"; } $header[] = "Cache-Control: max-age=0"; $header[] = "Connection: keep-alive"; $header[] = "Keep-Alive: 300"; $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; $header[] = "Accept-Language: en-us,en;q=0.5"; $header[] = "Pragma: "; // browsers keep this blank. curl_setopt($conn[$i], CURLOPT_URL, $url); curl_setopt($conn[$i], CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)'); curl_setopt($conn[$i], CURLOPT_HTTPHEADER, $header); unset($header); curl_setopt($conn[$i], CURLOPT_REFERER, 'http://www.google.com'); curl_setopt($conn[$i], CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($conn[$i], CURLOPT_AUTOREFERER, true); curl_setopt($conn[$i], CURLOPT_RETURNTRANSFER, 1); curl_setopt($conn[$i], CURLOPT_TIMEOUT, 20); curl_setopt($conn[$i], CURLOPT_NOPROGRESS, FALSE); curl_setopt($conn[$i], CURLOPT_WRITEFUNCTION,'progress_function'); curl_multi_add_handle ($mh,$conn[$i]); } do { $n=curl_multi_exec($mh,$active);/*killCheck();*/} while ($active); foreach ($urls as $i => $url) { $res[$i]=curl_multi_getcontent($conn[$i]); curl_multi_remove_handle($mh,$conn[$i]); curl_close($conn[$i]); } curl_multi_close($mh); return($res);//returns the array of result data, we will analyse this next } function killCheck() { if (file_exists('kill.txt')) { die("<br>Kill.txt found, Exiting..."); exit; } } function progress_function($ch, $string) { $length = strlen($string); echo "<br />Received $length bytes\n"; return $length; } //END Utility Functions ########################################################################################################################## //Program Functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function getURLsFromSectionMatch($result_array,$Host,$Schema,$message,$sectionRegEx) { $debug = $_GET['debug']; echo '<b>'.$message.'</b>'; foreach($result_array as $data) { killCheck();//so were not stuck in an infinite loop, there is at least a way out~ preg_match($sectionRegEx,$data,$sectionMatch); //print_r($result_array); if($sectionMatch) { echo '<br>Got Section...'; $section = $sectionMatch[1]; preg_match_all('/<a href="(.+?)"/si',$section,$linkMatch,PREG_SET_ORDER); foreach($linkMatch as $val) { if($Schema<>'' and $Host<>'') { $url = $Schema."://".$Host.$val[1]; } else { $url =$val[1]; } if($debug==1) { echo '<br>url ='.$url; } $arrayOfLinks[]=$url;//append to the array the link } } else { die("<br><b>Error, grabbing Section Match in the data:<br>$data"); } } return $arrayOfLinks; } //End Program Functions //Program Functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Phase Functions @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ function phase1() { } function phase2() { } function phase3() { $first_url[0]=$_GET['url'];//makes it a 1 index array~ $result_array = getResultsFromURLArray($first_url);//in this case array is only 1 item $parts = parse_url($first_url[0]);//must not be a relative link for the initial one~ $Host = $parts['host']; $Schema = $parts['scheme']; $category_links = getURLsFromSectionMatch($result_array,'','',"<br>Getting Category Links...",'/<h2>Company List - Company List<\/h2>(.+?)<\/div>/si'); $category_results = getResultsFromURLArray($category_links);//fills the result array $company_list_links = getURLsFromSectionMatch($category_results,$Host,$Schema,"<br>Getting Company List Links...",'/<div id="scontent">.+?<\/h2>(.+?)<\/div>/si'); $company_list_results = getResultsFROMURLArray($company_list_links);//fills the result array from all the company list links $company_page_links = getURLsFromSectionMatch($company_list_results,$Host,$Schema,"<br>Getting Page Links...",'/<div id="pagenav">(.+?)<\/div>/si'); } //End Phase Functions @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //End of Functions ------------------------------------------------------------------------------------------------------------------------------- //Main Code--------------------------------------------------------------------------------------------------------------------------------------- header('Content-Type: text/html; charset=utf-8');//so it prints all characters set_timeout_time($_Get['time']);//to prevent time outs switch ($_GET['option']) { case "stop": $ourFileName = "kill.txt"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); break; case "startover": if(file_exists("kill.txt")) { unlink("kill.txt"); echo '<br>File Kill.txt Deleted'; } else { echo '<br>No File Kill.txt to Delete'; } break; default: echo '<br>No Option Given'; } switch ($_GET['phase']) { case 1: echo "<br>Script Running for Phase 1"; phase1(); break; case 2: echo "<br>Script Running for Phase 2"; phase2(); break; case 3: echo "<br>Script Running for Phase 3"; phase3(); break; default: echo "<br>Unrecognizable Phase Number"; } //End Main Code------------------------------------------------------------------------------------------------------------------------------------ echo '<br><b>End of Script</b>'; ?> PHP:
Does anyone know at all? If you need me to clarify let me know, I think I can fix it on my own if I can see a sample of the write function working with RETURN TRANSFER on.
I fixed the problem, it has to do with my misunderstanding of the callback function. Apparently the callback function acts like the pipeline, by using a callback function I therefor have to manually deal with the data coming in. So for example, the webpage ebay.com or something, it may send me just the first parts of the page like the < html >< body > etc, and then the next time callback comes in, it sends the next bit of information, which makes sense this is how packets work after all. You send the information you want in sections at a time. The callback function gives you fine control over this which is why it confused me for so long. So you might need to use a global variable and keep appending the results to it. I was able to make it work now though, if anyone needs help and has a similar problem understanding it PM me and I'll assist.