[PHP] periodic file writing error (fputs)

2004-08-05 Thread Sarah Gray
Hello,

I am having a periodic problem that I cannot duplicate and wonder if
anyone has suggestions.

Once a sale is completed a record is written to a log file on the
server.

$filename = $dir. /. $logType._.$today..txt;
$fp = fopen($filename, a+);
fputs($fp, $logEntryStr);
fclose($fp);

The file is chmoded to 644.

About 3 out of 600 times, the log file is not written to.  The times
of day this happens are not consistent, and as I mentioned, I cannot
duplicate it when testing. I initially thought it was some kind of
error on the server, but I am beginning to think it is in my code.

Has anyone experienced anything like this or have any suggestions for
how to troubleshoot this?

Thanks,

Sarah

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] periodic file writing error (fputs)

2004-08-05 Thread Jay Blanchard
[snip]
I am having a periodic problem that I cannot duplicate and wonder if
anyone has suggestions.

Once a sale is completed a record is written to a log file on the
server.

$filename = $dir. /. $logType._.$today..txt;
$fp = fopen($filename, a+);
fputs($fp, $logEntryStr);
fclose($fp);

The file is chmoded to 644.

About 3 out of 600 times, the log file is not written to.  The times
of day this happens are not consistent, and as I mentioned, I cannot
duplicate it when testing. I initially thought it was some kind of
error on the server, but I am beginning to think it is in my code.

Has anyone experienced anything like this or have any suggestions for
how to troubleshoot this?
[/snip]

How do you know that it is not being written to? Do the transactions
show up in a database or some other form? Is it possible to have
duplicate log entries? What is $today, a date stamp, time date stamp,
epoch time stamp?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] periodic file writing error (fputs)

2004-08-05 Thread John W. Holmes
From: Sarah Gray [EMAIL PROTECTED]
 Once a sale is completed a record is written to a log file on the
 server.
 
 $filename = $dir. /. $logType._.$today..txt;
 $fp = fopen($filename, a+);
 fputs($fp, $logEntryStr);
 fclose($fp);

Consider this:

1. User A completes a transaction.
2. Script A reads the log file
3. User B completes a transaction
4. Script B read the log file
5. Script A write the new line to what was read in #2
6. Script B write the new line to what was read in #4

Now what's in the file? Only what Script B wrote.

http://us2.php.net/flock

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] periodic file writing error (fputs)

2004-08-05 Thread Jason Wong
On Friday 06 August 2004 02:50, Sarah Gray wrote:

 I am having a periodic problem that I cannot duplicate and wonder if
 anyone has suggestions.

 Once a sale is completed a record is written to a log file on the
 server.

 $filename = $dir. /. $logType._.$today..txt;
 $fp = fopen($filename, a+);
 fputs($fp, $logEntryStr);
 fclose($fp);

 The file is chmoded to 644.

 About 3 out of 600 times, the log file is not written to.  The times
 of day this happens are not consistent, and as I mentioned, I cannot
 duplicate it when testing. I initially thought it was some kind of
 error on the server, but I am beginning to think it is in my code.

 Has anyone experienced anything like this or have any suggestions for
 how to troubleshoot this?

- Enable full error reporting for PHP.

- Incorporate some error checking code as per example in manual for fwrite().

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Q:  How many Zen masters does it take to screw in a light bulb?
A:  None.  The Universe spins the bulb, and the Zen master stays out
of the way.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php