execute some webpage without opening it?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

execute some webpage without opening it?

Post by ddragas »

Hi all
How can I execute some webpage without opening it?

untill now I've used include("that_web_page"); bu I want to avoid this.

is it possible to do it with curl? I have checked for this on php.net - but could not wind answer

I'm on shared host.

Any suggestion is welcome.

Thank you all

regards ddragas
deadoralive
Forum Commoner
Posts: 28
Joined: Tue Nov 06, 2007 1:24 pm

Post by deadoralive »

If i understand you correctly curl will do what you want. have a look at http://www.php.net/curl for examples
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post by Jonah Bron »

Why don't you want to use include()?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

include() would allow the page requested to execute code. If it's a remote page, this is VERY bad. Using cURL, et al, avoids code execution in your instance of PHP.
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

web page with php script inside is on same server and under same domain. It should be executed in background.
This is for what I need it:
There is about 5000 recordsets that user inserts into one table, and here comes this script that should be executed in background. This script (from background) handle those recordsets, and if handled recordset is successfull, iz gets transfered to another table.

If I execute it with "include" user has to wait untill whole process finishes, and this could take a long time (depending from handle time).

What should I use then?

curl, exec ....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

cURL will wait for a response too (unless told otherwise.)

Look into using Snoopy to create a quick request to the page. http://snoopy.sf.net
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Re: execute some webpage without opening it?

Post by ddragas »

Thank you for reply, but I was unable to acomplish starting php script in background. Can you please help me? Snoopy did not work as it should. Problem is that if php script is run by cron job or by browser php script works great - if it is run by snoopy or curl it does nothing


Can you please suggest me right solution?

Thank you ion advance

Kind regards ddragas
kennaasoft
Forum Newbie
Posts: 2
Joined: Sun Jan 13, 2008 11:05 am

Re: execute some webpage without opening it?

Post by kennaasoft »

hi ddraggas, have you tried considering the use of Ajax? I think that is the most reasonable way to run processes asynchronously; plus, you also get a notification when the process is completed.
User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

Re: execute some webpage without opening it?

Post by jimthunderbird »

kennaasoft wrote:hi ddraggas, have you tried considering the use of Ajax? I think that is the most reasonable way to run processes asynchronously; plus, you also get a notification when the process is completed.
I agree, I used to use this approach a lot if I'm sure the client's browser will turn on javascript and AJAX support.
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Re: execute some webpage without opening it?

Post by ddragas »

Yes - you' re right.

Now I'm not big master of ajax, as this is my first contact with it

I've implemented it with ajax (prototype) but something is not working fine.
I'll try to describe problem.

First script (executable) is working ok, and after first script is done there is started second script - witch is not executed every time. I have noticed that when number of data posted from form to first script is big (10 000) - second script doesn't start, but if there is only submitted a few (<=20) then everything is working fine.

Code: Select all

 
<script src="../prototype/prototype.js" type="text/javascript"></script>
<script type="text/javascript">
function init () {
    $('Submit').onclick = function () {
        sendData();
        sendData1();
     }
}
function sendData () {
    var url = 'firstScript.php';
    var pars = Form.serialize('myForm');
    var myAjax = new Ajax.Request( url, {method: 'post', parameters: pars, onLoading: showLoad, onComplete: showResponse} );
}
function sendData1 () {
    var url = 'secondScript.php';
    var pars = Form.serialize('myForm');
    var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars} );
}
function showLoad () {
    $('load').style.display = 'block';
}
function showResponse (originalRequest) {
    var newData = originalRequest.responseText;
    $('load').style.display = 'none';
    $('status').innerHTML = newData;
}
 
 
</script>
 
 
this is code that uses ajax.

There is nothing wrong with php scripts (tested)

If somebody can help me I would appreciate it
Post Reply