Page 1 of 1
execute some webpage without opening it?
Posted: Thu Dec 20, 2007 2:45 pm
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
Posted: Thu Dec 20, 2007 3:36 pm
by deadoralive
If i understand you correctly curl will do what you want. have a look at
http://www.php.net/curl for examples
Posted: Thu Dec 20, 2007 4:04 pm
by Jonah Bron
Why don't you want to use include()?
Posted: Fri Dec 21, 2007 8:36 am
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.
Posted: Fri Dec 21, 2007 9:41 am
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 ....
Posted: Fri Dec 21, 2007 10:01 am
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
Re: execute some webpage without opening it?
Posted: Sat Jan 12, 2008 8:13 pm
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
Re: execute some webpage without opening it?
Posted: Sun Jan 13, 2008 11:29 am
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.
Re: execute some webpage without opening it?
Posted: Sun Jan 13, 2008 2:05 pm
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.
Re: execute some webpage without opening it?
Posted: Tue Jan 15, 2008 8:17 am
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