Hi All,
Is this the right forum for Nusoap-related questions?
I hope there is a simple answer to this very basic problem I am having. I have set up a simple test web service that queries a database and returns the query response to the web service client. Below are two scenarios - the first works and the second does not. What am I missing?
Scenario 1:
Web service contained in run_jobs.php (Unnecessary detail removed):
$lib_base_dir = "...";
require($lib_base_dir . '/libs/web_services/nusoap/nusoap.php');
$server = new soap_server;
$server->register('test1');
function test1() {
$conn = mysql_connect(...);
mysql_select_db(...);
$action_status = "connected";
$job_count = count_runnable_jobs();
$action_status = "jobs $job_count";
return $action_status;
}
function count_runnable_jobs() {
$current_dt = date("Y-m-d H:i:s");
$stmt = "select count(*) from JobQueue ";
$result = mysql_query($stmt);
if ($result) {
$row = mysql_fetch_row($result);
return $row[0];
}
}
Scenario 2:
Web service contained in run_jobs.php. Note that this has a require() directive - the only difference from above. The count_runnable_jobs function is contained within the required file jobs.php.
$lib_base_dir = "...";
require($lib_base_dir . '/libs/web_services/nusoap/nusoap.php');
require($lib_base_dir . '/libs/db/jobs.php'); // ********** Note this line added c/f above
$server = new soap_server;
$server->register('test2');
function test2() {
$conn = mysql_connect(...);
mysql_select_db(...);
$action_status = "connected";
$job_count = count_runnable_jobs();
$action_status = "jobs $job_count";
return $action_status;
}
// Function count_runnable_jobs contained in jobs.php
The client is as follows, replacing test1 with test2 for the second test:
$this_dir = dirname(FILE);
require_once($this_dir . '/../../libs/web_services/nusoap/nusoap.php');
$soapclient = new soapclient('......./run_jobs.php');
if($err = $soapclient->getError()){
echo "new soapclient error $err\n";
} else {
$ret_val = $soapclient->call('test1',array('debug'=>'1'));
if($err = $soapclient->getError()){
echo "soapclient call error $err\n";
} else {
echo "returned $ret_val\n";
}
}
Results:
test1:
returned jobs 1
test2:
returned // ie. empty string returned from web service
What am I doing wrong? Why does the require() directive make a difference?
Thanks in anticipation.
Colin Goldberg