Open a site and wait

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.
<?php
//Not the actual code, but same results
 
set_time_limit(0);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/page.shtml");
curl_exec($ch):
 
sleep(120);
 
curl_close($ch);
echo "Page viewed for 120 seconds";
 
?>

Open in new window

LVL 1
HaloShgAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

OpalelementCommented:
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?
0
HaloShgAuthor Commented:
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.
0
OpalelementCommented:
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.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

HaloShgAuthor Commented:
Do you have an example?  I'm not sure what you mean. What would I post?
0
OpalelementCommented:
What is the URL of the page you are sending the cURL request to?
0
HaloShgAuthor Commented:
I cannot provide that information. It's a password protected page (you have to login) and I cannot give you the login credentials.
0
OpalelementCommented:
If it is password protected how do you get by it with curl?
0
HaloShgAuthor Commented:
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_COOKIEFILE,1);
// LOGIN
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "USERNAME=$username&PASSWORD=$password");
// Execute and close
$output = curl_exec($ch);
curl_close($ch);

Open in new window

0
OpalelementCommented:
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.
0
HaloShgAuthor Commented:
I found a solution. I just popped an IFrame of the page onto my page and then delete it once 120 seconds have passed. Works now :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.