I have an issue when I use fgets to open a STDIN stream from an iSeries box. It works all fine and well - I get my data and do stuff with it. However! I want to create an error log via a flat file ie .txt but I am unable to create that file??
I'm most likely missing something but I think having that STDIN stream open is blocking me from creating a flat file. So, my thought was to use fclose to stop that stream after I receive my data.
Here is my code condensed :
//DEFINE STANDARD INPUT
if( !defined( "STDIN" ) ) {
define( "STDIN", fopen( 'php://stdin', 'r' ) );
}
//GET STANDARD INPUT FROM AS/400
$input = fgets(STDIN);
//BREAK DATA INTO AN ARRAY - SEPERATED BY ' ! '
$data = explode('!', $input);
//SET ACCT NO VARIABLE
$acctNO = rtrim($data[0]);
//GET EMAIL TYPE - EITHER 1 OR 2
$emailType = rtrim($data[1]);
// GETTING DATA
// DOING STUFF
// ERROR CHECKING
// BLAH BLAH
if(isset($error) && $error == 'YES'){
//setup error log and email alert
//SENDING EMAIL NOTICE OF ERROR
mail ($to, $subject, $msgErr, $mailheaders);
// ATTEMPTING TO CLOSE STANDARD INPUT STREAM
// ###### PROBLEM AREA ######
fclose(STDIN);
fclose(STDOUT);
fclose(STDERR);
fclose($input);
$date = date('Ymd');
//#####################
//#####################
//
//WRITE ERROR MSG TO ERROR LOG
//
//#####################
//#####################
$fileName = "error_".$date.".txt";
$file = fopen($fileName, 'w');
fwrite($file, "Business Name: ".$bname."\n");
fwrite($file, "Acct No.: ".$acctNO."\n\n");
fwrite($file, "-----------------------------\n\n");
fwrite($file, "Error MSG: \n\n");
foreach($errMsg as $em){
fwrite($file,"".$em."\n");
}
fclose($file);
}
//NO ERRORS SEND EMAIL
else{
When I add the 'fclose' same outcome. Script runs fine but doesn't create the .txt file.
The other odd thing I think associated to this is... I cannot use 'includes' or 'requires', it will bomb out on the 400 side. Though, I can call the DB get data, mail info, etc.. but I cannot include or write to a .txt file. Not sure what is happening. Maybe Dr. Egon Spengler has something to do with this?
fyi.. This script is called via RPG & CL.
I appreciate any insight.
Happy ? day!