We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Open a site and wait

HaloShg asked
Medium Priority
Last Modified: 2012-05-07
I am currently stuck at this PHP script. I need to open a website and emulate viewing it for 120 seconds.

For the rest of the script cURL is being used.

The problem comes that when waiting for a while, PHP decides  to cut off the rest of the script. The page is not viewed for 120 seconds.

Oh, and this will also be a cron job, so I don't think you can just use JS to open a new window and wait at it for 120 seconds.

I don't care how this site it viewed, but it must register being viewed for 120 seconds.
//Not the actual code, but same results
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/page.shtml");
echo "Page viewed for 120 seconds";

Open in new window

Watch Question

So if I understand you correctly and I am reading the code correctly, it opens the page for only a second and then closes the page, but then just sleeps the main script for 120 seconds?

Why do you need it to stay open for 120 seconds?


Yes, you are correct, and that's what I need to fix.

It is being used on a remote page. That page has a "timer" and wont add the values to it's own database unless you wait 120 seconds.

Sort of like those download timers on pages like RapidShare, however, there is no download at the end, it will just add values.

This script is an automation script, in general. It should be working at midnight every day, so it will be a cron job.
I don't think cURL can freeze like that. It goes to the page and can return values but between sending and receiving data it can't do anything else from the script. I'm sure you can just make the page think you waited by sending Post variables straight to it or something.


Do you have an example?  I'm not sure what you mean. What would I post?
What is the URL of the page you are sending the cURL request to?


I cannot provide that information. It's a password protected page (you have to login) and I cannot give you the login credentials.
If it is password protected how do you get by it with curl?


I accept the cookies and login using post
$username = 'username';
$password = 'password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://WEBSITE.com/cgi-bin/password.cgi");
// Accept cookies
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "USERNAME=$username&PASSWORD=$password");
// Execute and close
$output = curl_exec($ch);

Open in new window

On teh page with the countdown, what happens when it finishes? What I'm guessing happens is that it submits a hidden form with the data. Using cURL, you could get the source of this page, get the data for the form, and then use that in a new cURL script.
Unlock this solution and get a sample of our free trial.
(No credit card required)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.