Forum Moderators: coopster
<?php
//step1
$cSession = curl_init();
//step2
curl_setopt($cSession,CURLOPT_URL,"https://www.example.com/some_URI/");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false);
//step3
$result=curl_exec($cSession);
//step4
curl_close($cSession);
//step5
echo $result;
?>
about the accuracy of using the "strstr" function
# CODE FROM PHP MANUAL COMMENT
function findZero($numberString) {
if (strstr($numberString, '0')) {
echo 'found a zero';
} else {
echo 'did not find a zero';
}
}
if (strstr($numberString, '0') !== false) {
function findZero($numberString) {
if (strstr($numberString, '0') === false) {
echo 'did not find a zero';
} else {
echo 'found a zero';
}
}
You can simply call the curl function every time the page in question is requested
That being said, and unrelated to the question. When someone wants to make a page, showing the availability of such or such product from another site, this is not a good idea to run the curl command on page requests. This will slow down the page, and if the remote site is slow, or off line, it can make your own page unreachable / timeout. So , in all events, this is always better to run this kind of processing in the background, in a cron script, store the result , and use this result, when a page is displayed.
If you are saying that PHP requires a cron script,
You can also run asynchronous code in PHP but, if the distant site that you are fetching takes 5 seconds, to answer, it will still delay your script by 5 seconds since you will need to wait before showing the result on your page.
Also, if you fetch a distant script for each of your page requests, this is overwhelming the distance site, and this is not really nice behavior. if you page is visited 1000 times a day, you'll call the distant site 1000 times?