strago Posted April 30, 2010 Share Posted April 30, 2010 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 More sharing options...
947740 Posted April 30, 2010 Share Posted April 30, 2010 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. Link to comment https://forums.phpfreaks.com/topic/200305-using-php-curl-to-fetch-urls/#findComment-1051191 Share on other sites More sharing options...
Ken2k7 Posted April 30, 2010 Share Posted April 30, 2010 curl_multi_init Link to comment https://forums.phpfreaks.com/topic/200305-using-php-curl-to-fetch-urls/#findComment-1051203 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.