HuntsvilleMan Posted May 5, 2011 Share Posted May 5, 2011 I have an application which runs on more than one server and need to launch one PHP script from another PHP script. Since this is different than a function call I'm not sure how it's done. I plan to include parameters in the URL I send and use GETs to pick up parameters in the "called" PHP script. Thanks for sugestions Quote Link to comment Share on other sites More sharing options...
wright67uk Posted May 5, 2011 Share Posted May 5, 2011 Could you use include? <?php include('file1.php'); ?> OR <?php include($_SERVER['DOCUMENT_ROOT'].'/include/file2.php'); ?> Quote Link to comment Share on other sites More sharing options...
markjoe Posted May 5, 2011 Share Posted May 5, 2011 so you really only need to call a url? you can do this many ways depending on what exactly you need. You could use cURL. http://us2.php.net/manual/en/ref.curl.php You could use exec or similar function to call a program such as wget. Do you need to read a response back or just send the request and not wait? Quote Link to comment Share on other sites More sharing options...
HuntsvilleMan Posted May 5, 2011 Author Share Posted May 5, 2011 Thanks for the sugestion although understanding it is a bit beyond me for now. I'll read the curl description a few more times. Hope to get it. What I would like to do is launch another PHP script and exit while sending some parameters along in a url. Guess I never thought about what's involved since I always launched the first PHP script with a url from my browser. As I read over the curl library it looks like they have what I'm trying to do but for lack of a simple example I can play with, it's quite mystifying. Do you have a simple example in which one PHP script starts another PHP script in the same directory. The idea of using includes looks nice except for potential variable or function conflicts. Thanks for an example. Mike Quote Link to comment Share on other sites More sharing options...
fugix Posted May 5, 2011 Share Posted May 5, 2011 what potential variable/function conflicts are you talking about? Quote Link to comment Share on other sites More sharing options...
spiderwell Posted May 6, 2011 Share Posted May 6, 2011 includes is what you are after i think really it turns 2 pages into one, which really is like going from one to another which is what you want isnt it? Quote Link to comment Share on other sites More sharing options...
markjoe Posted May 6, 2011 Share Posted May 6, 2011 I had the impression the 2nd script you are calling was on a different server. Is this not correct? Quote Link to comment Share on other sites More sharing options...
HuntsvilleMan Posted May 6, 2011 Author Share Posted May 6, 2011 My first objective is to launch (if that's the right word) one PHP script from another without using an include. My first objective is to first do it on the same server. After understanding that I would like to try it across servers. Essentially, I would like to have a PHP script do what my browser does when it sends a url to a PHP script. No doubt there is more going on in this interaction than I appreciate. Quote Link to comment Share on other sites More sharing options...
markjoe Posted May 6, 2011 Share Posted May 6, 2011 from http://us2.php.net/manual/en/function.curl-init.php <?php // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, "http://www.example.com/"); curl_setopt($ch, CURLOPT_HEADER, 0); // grab URL and pass it to the browser curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch); ?> here is a list of options: http://us2.php.net/manual/en/function.curl-setopt.php If you don't want to send output to the browser, use option CURLOPT_RETURNTRANSFER to return a string from curl_exec instead. Using curl, what server the target script runs on makes no difference. It is simply making the HTTP request, just like your browser does. Quote Link to comment Share on other sites More sharing options...
markjoe Posted May 6, 2011 Share Posted May 6, 2011 Oh and if you want to let your local script to continue to run and not wait for the remote page to return use the curl_multi_exec <?php // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, "http://www.example.com/"); curl_setopt($ch, CURLOPT_HEADER, 0); //create the multiple cURL handle $mh = curl_multi_init(); curl_multi_add_handle($mh,$ch); $is_done = 0; curl_multi_exec($mh,$is_done); // close cURL resource, and free up system resources curl_multi_remove_handle($mh, $ch1); curl_multi_close($mh); ?> make sure you read the docs, this is just thrown together with no testing, it's even been a while since I've worked with curl. But this should be very close to a viable solution. Quote Link to comment Share on other sites More sharing options...
wright67uk Posted May 8, 2011 Share Posted May 8, 2011 includes is what you are after i think really it turns 2 pages into one, which really is like going from one to another which is what you want isnt it? I put an example of include above, maybe you could use include and post some variables; includename.php?variable=$variable&variable2=$variable2 Why did you say you didnt want to use include? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.