Jump to content

Using php curl to fetch URLs.


strago

Recommended Posts

Is this code correct for getting and executing multiple URLs, and is there any way to shorten it to having the $ch fetch each URL instead of making a new $ch for each URL??

<?php
$ch = curl_init('http://www.whatever.com/');
curl_exec($ch);
curl_close($ch);

$ch2 = curl_init('http://www.whatever.com');
curl_exec($ch2);
curl_close($ch2);

$ch3 = curl_init('http://www.whatever.com');
curl_exec($ch3);
curl_close($ch3);
?>

 

I'm just trying to have one php script be the file my servers cron job get's instead of a bunch of different URLs, and so I don't have to come on SSH and update the cron file every time I wanna change it. FTPs much easier!

Link to comment
https://forums.phpfreaks.com/topic/200305-using-php-curl-to-fetch-urls/
Share on other sites

Use a function?

 


function getURL($url) {
$ch = curl_init('http://www.whatever.com/');
curl_exec($ch);
curl_close($ch);
return $ch;
}
$ch = getURL("http://somewhere.com");

 

I don't know much about curl, nor what you are trying to do, but it would seem a function would be a good way to minimize the code you have going on.

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.