I have an application which has performed fine in two test environments but only works intermittently on a live environment. In order to debug I created the script below to test the area of the main application that fails.
Basically it has to call a shell script on the UNIX environment which sets some environment variables and then it has to call an executable which performs a password reset on an application called Siebel Analytics. The problem is that it sometimes runs and sometimes comes back with an “Unable to fork” error. I have spent 3 days tearing my hair out trying to find out what causes it but no luck. The live environment and one of the test environments are identical but the issue only seems to occur on live which makes me think it may be down to the fact that Live has more concurrent users although the web server only ever shows around 5% CPU usage
You’ll be able to see a couple of functions I’ve tried to use instead of system() but they aren’t any more successful
Any help much appreciated
<?php
// set the error level to show everything
error_reporting(E_ALL);
$runShell = 'yes';
$runChangePassword = 'yes';
$useBasicSystem = 'yes';
$shellResult = '';
$shellResult2 = '';
$shellResult3 = '';
$shellResult4 = '';
// print header and page title
echo '<html><head><title>';
if ($_SERVER['HTTP_HOST'] == 'xxx.xxx.xxx.xxx')
{
echo 'REF';
$shellScriptExe = '/websrvr_iplanet/analytics753110/Web/Servlet/php/sa-cli.sh';
$passwordChangeLocation = '/websrvr_iplanet/analytics753110/Bin/nqschangepassword.exe';
} else {
echo 'LIVE';
$shellScriptExe = '/appserver_iplanet/analytics753110/Web/Servlet/php/sa-cli.sh';
$passwordChangeLocation = '/appserver_iplanet/analytics753110/Bin/nqschangepassword.exe';
}
echo '</title>
<style type="text/css">
body, body td {
font: normal 12px Verdana;
color: #333333;}
h1 {
color: #ff6600;
font: bold 14px Verdana;
margin: 20px 0 5px 0;
padding: 3px;
background: #ededed;
border-bottom: 1px #aaaaaa solid;}
h2 {
color: #003366;
font: bold 12px Verdana;
margin: 10px 0 0 0;}
</style>
</head>';
function mysystem($command)
{
if (!($p=popen($command,"r")))
{
return 126;
}
$out = '';
while (!feof($p))
{
$line=fgets($p,1000);
$out .= $line;
}
pclose($p);
return $out;
}
function mysystem2($command, $hide=false)
{
if ( !($p=popen("($command)2>&1","r")) )
{
return 126;
}
while (!feof($p))
{
$l=fgets($p,1000);
if (!$hide)
{
print $l;
}
}
return pclose($p);
}
if ($runShell == 'yes')
{
// define shell script location
$shellResult = '<h1>SHELL SCRIPT ['.date('d-m-Y H:i:s').']</h1><strong>Shell Script Command</strong><br />'.$shellScriptExe.'<br />
<h2>Shell Script Results</h2><pre>';
echo $shellResult;
if ($useBasicSystem == 'no')
{
$shellScript = mysystem ($shellScriptExe);
$shellResult2 = '</pre><strong>Result: </strong>'.$shellScript;
} else {
$shellScript = system ($shellScriptExe, $ret);
$shellResult2 = '</pre><strong>Command: </strong>'.$shellScript.'<br /><strong>Return Value: </strong>'.$ret;
}
echo $shellResult2;
}
if ($runChangePassword == 'yes')
{
$shellResult3 = '<h1>PASSWORD CHANGE ['.date('d-m-Y H:i:s').']</h1>';
// define password change location
$params['dsnName'] = 'AnalyticsWeb';
$params['dbUser'] = 'USER1';
$params['oldPassword'] = 'PASSWORD';
$params['newPassword'] = 'PASSWORD2';
$shellResult3 .= '<strong>Parameters being passed to the password change executable</strong>
<table>';
foreach ($params as $key=>$value)
{
$shellResult3 .= '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';
}
$shellResult3 .= '</table><br />';
$passwordChangeExe = $passwordChangeLocation.' -d '.$params['dsnName'].' -u '.$params['dbUser'].' -p '.$params['oldPassword'].' -n '.$params['newPassword'];
$shellResult3 .= '<strong>Password Change Command</strong><br />'.$passwordChangeExe.'<br />
<h2>Password Change Results</h2><pre>';
echo $shellResult3;
if ($useBasicSystem == 'no')
{
$passwordChange = mysystem ($passwordChangeExe);
$shellResult4 = '</pre><strong>Result: </strong>'.$passwordChange;
} else {
$passwordChange = system ($passwordChangeExe,$ret2);
// $shellResult4 = `$passwordChangeExe; echo $?`;
$shellResult4 = '</pre><strong>Command: </strong>'.$passwordChange.'<br /><strong>Return Value: </strong>'.$ret2;
}
echo $shellResult4;
}
$file = fopen('shell_log.htm','a+');
if (!fwrite ($file,$shellResult.$shellResult2.$shellResult3.$shellResult4))
{
echo 'Could not write result to file';
}
fclose($file);
echo '<body></body></html>';
?>