automation - How do I get php to simulate a visit to a url?Get the solution ↓↓↓
I set up a crontab to execute a php file every minute. Now I need to create the php file but I’m clueless on what the contents should be.
All the code needs to do is visit the website url. No need to save anything. It just needs mimic loading the home page just like a browser would. That in turn triggers a chain of events which are already in place. It is an extremely low traffic site so that’s the reason for it.
I know, I could do it with curl. But for reasons I won’t get into, it needs to be a php file.
Can anyone point me in the right direction please. Not expecting you to provide code, just direction.
You can use curl in PHP to just send a request to the page:
$curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, "the.url-of-the-page.here"); curl_exec($curl_handle); curl_close($curl_handle);
You could also do it with one line (note that the whole HTML of the page is retrieved which takes a bit longer):
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:184.108.40.206) Gecko/20080311 Firefox/220.127.116.11');
Marco M is right, but there is a catch (it may not be for most but there is sometimes)
normally does the trick (i use that more than i should) BUT ! There is a setting in php.ini that needs to be on for that function to enable it to open URLs ! I had that once with a webhoster, they did not allow that ;)
Share solution ↓
Link To Answer People are also looking for solutions of the problem: call to a member function update() on null
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.