Jump to content

fwrite issue


schilly

Recommended Posts

I'm writing a bounce email tracker for newsletters using email piping. I'm trying to write the bounce emails to a log file for reference but for some reason it's not writing to the file. It tells me it's writing to the file but the content isn't there.

#!/usr/bin/php
<?php

//include bounce class
require_once("bounce_driver.class.php");

// read in the bounce from stdin
$fd = fopen("php://stdin", "r"); //fopen("bounce_test2.txt", "r");
$email = "";
while (!feof($fd)) {
    $email .= fread($fd, 1024);
}
fclose($fd);

$bounce_info = Bouncehandler::get_the_facts($email);

$bounce_type = $bounce_info[0]['action'];
$bounce_email = $bounce_info[0]['recipient'];
$timestamp = date('H:i:s M j, Y', time());
$debug_line = "$timestamp - $bounce_email - $bounce_type\n";

if(!$handle = fopen('bounce_log.txt','a'))
 mail('email','Bounce Debug','could not open file');

$fw = fwrite($handle,$debug_line);
if(!$fw)
 mail('email','Bounce Debug','write error');
fclose($handle);

//debug
mail('email','Bounce Debug',"num bytes written = $fw\n\n$debug_line\n\n" . print_r($bounce_info,true));

//commented out db code.
?>

 

So I've set up a ton of debug stuff. The fopen and fwrite calls don't send me any email so it doesn't seem like any errors there. The debug email tells me that bytes are being written.

 

Debug Email

num bytes written = 70

12:12:15 Jan 29, 2010 - whatwhat@asdflkajsdflaksdfjalsdf.com - failed


Array
(
   [0] => Array
       (
           [recipient] => whatwhat@asdflkajsdflaksdfjalsdf.com
           [status] => 5.1.2
           [action] => failed
       )

)

 

But if I look at the file the line isn't there. The file was originally 644 but I changed it to 777 with no differences.

 

Any ideas?

 

Thx.

Link to comment
Share on other sites

ok it seems like it can't save the file for some reason.

 

i tried to see if it was an error on closing the file but nope.

 

the timestamp on the file isn't changing though so it definitely isn't writing out properly.

 

would the mail user have rights to do this inside someone elses user account if the perms are set right?

 

Oh and I meant the file was 622 above.

 

I tried deleting the file and php wasn't able to create a new one so it seems like a permissions thing. Any UNIX people shed some light on this?

Link to comment
Share on other sites

1=execute

2=read

4=write

622

owner-group-world/others

6 owner can read/write

2 group can read

2 world/others can read

 

Looking at your code what are you taking in on the command line?

 

$fd = fopen("php://stdin", "r");

$fd_str = fgets($fd, 255);

fclose($fd);

echo "$fd_str";

 

Do you get the mail out to the screen?

 

 

HTH

Teamatomic

Link to comment
Share on other sites

ok i set said it right in the first place(couldn't remember if the 3rd bit was read or write). all users have write access to the file (644) but even 777 didn't help.

 

the command line is taking in the whole email. my bounce@ email account is being piped to this script.

 

the bounce class parses the email and figures out what the failed address is and if it's a soft error (mailbox full) or hard error (mailbox doesn't exist). then i update our newsletter flag accordingly.

 

im not sure why i can't write to this file. i pretty much gave up on friday because i wasted too much time on it. the only reason i did this instead of just emailing myself the debug (which works) was because i was expecting about 25k bounces from one of our newsletters.

 

i really think it's related to privs in the different user accounts.

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.