?
Solved

Open a site and wait

Posted on 2009-07-04
10
Medium Priority
?
270 Views
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.
<?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

0
Comment
Question by:HaloShg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 5

Expert Comment

by:Opalelement
ID: 24777206
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
 
LVL 1

Author Comment

by:HaloShg
ID: 24777223
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
 
LVL 5

Expert Comment

by:Opalelement
ID: 24777249
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
WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

 
LVL 1

Author Comment

by:HaloShg
ID: 24777257
Do you have an example?  I'm not sure what you mean. What would I post?
0
 
LVL 5

Expert Comment

by:Opalelement
ID: 24777270
What is the URL of the page you are sending the cURL request to?
0
 
LVL 1

Author Comment

by:HaloShg
ID: 24777307
I cannot provide that information. It's a password protected page (you have to login) and I cannot give you the login credentials.
0
 
LVL 5

Expert Comment

by:Opalelement
ID: 24777350
If it is password protected how do you get by it with curl?
0
 
LVL 1

Author Comment

by:HaloShg
ID: 24777356
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
 
LVL 5

Expert Comment

by:Opalelement
ID: 24780865
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
 
LVL 1

Accepted Solution

by:
HaloShg earned 0 total points
ID: 24806870
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

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question