Question : How to run my script from another script and wait for finish?

I need to call a script called build_report.php, pass in a URL variable named partno and wait until it is finished before continuing.

This script builds a report and then an email is sent out to our customer so I don't want the email sent until the report is generated.

Is this possible?

Which should I use exec or cURL?

Answer : How to run my script from another script and wait for finish?

With an URL variable I take it you mean a GET parameter, like build_report.php?partno=12345.

AFAIK, you can't pass GET data when calling PHP from the command line, so you'd have to use cURL. Attached is a small example of how you could do this with cURL. The curl_exec() function returns after the page was fully retrieved, so the report should be generated after calling it.
1:
2:
3:
4:
5:
6:
7:
8:
$curlhandle = curl_init("http://url.to/build_report.php?partno=".urlencode($partno));
if ($curlhandle === false) {
	die("Could not create a cURL handle!");
}
if (curl_exec($curlhandle) === false) {
	die("Could not connect to the build_report script!");
}
curl_close($curlhandle);
Random Solutions  
 
programming4us programming4us