I am trying to run a java client through PHP which sends an XML to another server. It typically takes about 10 – 30 seconds to receive the response. When I run the PHP I can tell that there is no load time so I am thinking the rest of the code executes before the response is received. I am attempting to have the return response displayed in the browser and be written to another XML in the same directory. None of this happens. The new XML is created, but is empty.
$output = shell_exec("java SOAPClient4XG http://turbolink.turbo-marketing.net:8180 getList.xml");
sleep(30);
echo $output;
$filename = "getListResult";
$filename .= ".xml";
$fp = fopen($filename, 'w');
fwrite($fp, $output);
fclose($fp);
I added sleep(30) to give the java a chance to finish before passing the value into $output but it doesn’t help. The command java SOAPClient4XG http://turbolink.turbo-marketing.net:8180 getList.xml" works. I have used it in SOAP UI and through PUTTY by running it in the directory. The output I receive is this, in XML / SOAP format:
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<n1:getListsResponse xmlns:n1="urn:Turbolink"
env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<getListsResult xsi:type="n1:getListsResult">
<responseMessages n2:arrayType="n1:responseMessage[1]"
xmlns:n2="http://schemas.xmlsoap.org/soap/encoding/"
xsi:type="n2:Array">
<responseMessage>
<code xsi:type="xsd:string">0</code>
<message xsi:type="xsd:string">No Error</message>
</responseMessage>
</responseMessages>
<dataLists xmlns:n3="http://schemas.xmlsoap.org/soap/encoding/"
xsi:type="n3:Array"
n3:arrayType="n1:dataList[5]">
<dataList>
<listID xsi:type="xsd:string">CVPLUS </listID>
<listDescription xsi:type="xsd:string">ConsumerVision Plus</listDescription>
<listVersion xsi:type="xsd:integer">94</listVersion>
</dataList>
<dataList>
<listID xsi:type="xsd:string">MORTHOT </listID>
<listDescription xsi:type="xsd:string">Mortgage Hotlines</listDescription>
<listVersion xsi:type="xsd:integer">206</listVersion>
</dataList>
<dataList>
<listID xsi:type="xsd:string">MRTGBASE</listID>
<listDescription xsi:type="xsd:string">Mortgage Base</listDescription>
<listVersion xsi:type="xsd:integer">94</listVersion>
</dataList>
<dataList>
<listID xsi:type="xsd:string">SUPERNEW</listID>
<listDescription xsi:type="xsd:string">American New Movers Plus</listDescription>
<listVersion xsi:type="xsd:integer">171</listVersion>
</dataList>
<dataList>
<listID xsi:type="xsd:string">TSEBUS </listID>
<listDescription xsi:type="xsd:string">TSE Business File</listDescription>
<listVersion xsi:type="xsd:integer">38</listVersion>
</dataList>
</dataLists>
</getListsResult>
</n1:getListsResponse>
Is there a way I can wait until $output has some value before moving on? When I put an isset($output) conditional I can see that the variable is never set. I tried calling the shell_exec() again inside the conditional but I still get nothing.
*edit: The server has IP restrictions so trying to run this code on your machine will not work exactly the same. You will / should get an error response though.
I had put the java file in my server env path. Also, making an absolute path to it with
/jdk1.6.0_14/bin/java SOAPClient4XG http://......worked as well.