Q:

How to execute a php script from another php script by using the shell? 

I have a php file called sample.php with the following content:
<? php
echo "Hello World!"; 
? >

And what I want to do, is to run this php script using a second php script.  
I think shell_exec could help me, but I don't know its syntax.  
By the way, I want to execute this files with cpanel.  So I have to execute the shell.  
Is there any way to do this? 

A:

If you need to write a php file's output into a variable use the ob_start and ob_get_contents functions.  See below:
<? php
    ob_start();
    include('myfile.php');
    $myStr = ob_get_contents();
    ob_end_clean();
    echo '>>>>' .  $myStr . ' <<<<';
? >

So if your 'myfile.php' contains this:
<? php
    echo 'test';
? >

Then your output will be:
>>>>test<<<<

A:

You can use cURL for remote requests.   The below is from php.net:
<? 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's a good tutorial: http://www.sitepoint.com/using-curl-for-remote-requests/
Consider watching this YouTube video here as well:  http://www.youtube.com/watch?v=M2HLGZJi0Hk

