Jump to content

Recommended Posts

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

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?

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

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.

 

 

 

 

 

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.

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.

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.