Jump to content

Problem with a Curl script


ChrisF79

Recommended Posts

Hello:

 

I have a script that I run to pull images down off of the local Realtor MLS.  It works fine but it outputs all fo these errors.

 

The part of the code that does it is:

			// Build the $urls array //		
		$i = 101;
		$stop = 101 + $num_images - 1;
		while ($i <= $stop) {
			$img = 'http://www.sunshinemls.com:8081/pphotos/'.$pieces[1].'/'.$mls_number.'.'.$i.'.jpg';
			$urls[] .= $img;
			$i = $i + 1;
		}

		// Use Curl To Save The Files Locally //
		$save_to = $fullpath;
		$mh = curl_multi_init();
		foreach ($urls as $i => $url) {
		    $g=$save_to.basename($url);
		    if(!is_file($g)){
		        $conn[$i]=curl_init($url);
		        $fp[$i]=fopen ($g, "w");
		        curl_setopt ($conn[$i], CURLOPT_FILE, $fp[$i]);
		        curl_setopt ($conn[$i], CURLOPT_HEADER ,0);
		        curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,60);
		        curl_multi_add_handle ($mh,$conn[$i]);
		    }
		}
		do {
		    $n=curl_multi_exec($mh,$active);
		}
		while ($active);
		foreach ($urls as $i => $url) {
	    curl_multi_remove_handle($mh,$conn[$i]);
	    echo '<p>$i = ' . $i . '<br />$mh = ' . $mh . '<br />$conn[$i] = '.$conn[$i].'</p>';
		    curl_close($conn[$i]);
		    fclose ($fp[$i]);
		}
		curl_multi_close($mh);

 

That gives me the following errors:

Warning: curl_close(): supplied argument is not a valid cURL handle resource in /home/chrisfar/public_html/lister/process_listing.php on line 653

Warning: fclose(): supplied argument is not a valid stream resource in /home/chrisfar/public_html/lister/process_listing.php on line 654

Warning: curl_multi_remove_handle() expects parameter 2 to be resource, null given in /home/chrisfar/public_html/lister/process_listing.php on line 651

 

I put some statements in there to echo the variables to make sure it's working and when I do a print_r of $url I get this:

Array ( [0] => http://www.sunshinemls.com:8081/pphotos/78/209030178.101.jpg [1] => http://www.sunshinemls.com:8081/pphotos/78/209030178.102.jpg [2] => http://www.sunshinemls.com:8081/pphotos/78/209030178.103.jpg [3] => http://www.sunshinemls.com:8081/pphotos/78/209030178.104.jpg [4] => http://www.sunshinemls.com:8081/pphotos/78/209030178.105.jpg [5] => http://www.sunshinemls.com:8081/pphotos/78/209030178.106.jpg [6] => http://www.sunshinemls.com:8081/pphotos/78/209030178.107.jpg [7] => http://www.sunshinemls.com:8081/pphotos/78/209030178.108.jpg ) 

 

Then, I output the other variables to make sure and I get this:

$i = 1
$mh = Resource id #7
$conn[$i] =

 

For whatever reason, it just isn't getting the $conn[$i] and leaving it blank.  Any idea how I can fix this?  I'm stumped :(

Link to comment
https://forums.phpfreaks.com/topic/198568-problem-with-a-curl-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.