For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > August 2007 > fopen()









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author fopen()
Kevin Raleigh

2007-08-17, 10:00 pm

Is there something that says that I can only have only one file
open at a time?

The reason I ask is if I run two file open connections at the same time
my emailAddresses.txt file is read, but none of my emails are sent.
All of the data ends up in my error_file_log.txt. If I comment out the
second fopen() stream used for my error log my email program
works fine. Very strange behavior...

And while I am on the subject this code:
$file_emailErr = @fopen("emailErrorLog.txt", "a") or exit("Unable to open
file!");
$subject = "\n\n" . "Subject: " .$subject .
" \n**************************************
**********************\n";
@fwrite($file_emailErr, $subject);

outputs this text:

Subject: test 2
****************************************
********************

This code
if(!$mail->Send()){
$myString = $emailAdd . "\t" . $myName . "\n";
fwrite($file_emailErr, $myString);
}
outputs this text:
kraash@mysite.net
Kevin
asdf@asdf.com
Jone
qwer@asdfa.net
Jack
kraash@mysite.net
Kevin

Why is the name written to a newline in the second code example, but the
first
example works as it should?

insight always appreciated
thank you
Kevin


Rik

2007-08-18, 4:01 am

On Sat, 18 Aug 2007 04:37:29 +0200, Kevin Raleigh <kraleigh@sbcglobal.ne=
t> =

wrote:

> Is there something that says that I can only have only one file
> open at a time?
>
> The reason I ask is if I run two file open connections at the same tim=

e
> my emailAddresses.txt file is read, but none of my emails are sent.
> All of the data ends up in my error_file_log.txt. If I comment out the=


> second fopen() stream used for my error log my email program
> works fine. Very strange behavior...


Should be no problem unless you get a variable clash...
This works perfectly:

<?php
$a =3D fopen(dirname(__FILE__).'/a','w');
$b =3D fopen(dirname(__FILE__).'/b','w');
fwrite($a,'This is a');
fwrite($b,'This is b');
fclose($a);
fclose($b);
?>


> And while I am on the subject this code:
> $file_emailErr =3D @fopen("emailErrorLog.txt", "a") or exit("Unable to=

open
> file!");
> $subject =3D "\n\n" . "Subject: " .$subject .
> " \n**************************************
**********************\n";
> @fwrite($file_emailErr, $subject);
>
> outputs this text:
>
> Subject: test 2
> ****************************************
********************
>
> This code
> if(!$mail->Send()){
> $myString =3D $emailAdd . "\t" . $myName . "\n";
> fwrite($file_emailErr, $myString);
> }
> outputs this text:
> kraash@mysite.net
> Kevin
> asdf@asdf.com
> Jone
> qwer@asdfa.net
> Jack
> kraash@mysite.net
> Kevin
>
> Why is the name written to a newline in the second code example, but t=

he
> first
> example works as it should?


2 options:
1. There's a newline char in $emailAdd.
2. There is no actual newline, it's just how it looks due to wrapping in=
=

the viewport.
-- =

Rik Wasmus
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com