Jump to content

PHP CLI and email piping dropping calls to script


tadakan

Recommended Posts

I'm working on processing emails nearly instantaneously with a PHP CLI script that gets called by an email pipe.  The email pipe is in hmail server.  The script parses the email and then writes some bits into a text file.

 

The problem I'm having is that if I send several emails in quick succession only the first one seems to interact with the script.  The rest don't result in any behavior.  I initially thought that my problem was with php's interaction with the text file so I tried writing some extra code to create a temp file and then copy it to the directory, but that doesn't seem to have changed the behavior at all so I'm wondering if it may be the email pipe that's the problem but I'm not sure how to go about tracking down the problem.

 

Sorry for the run on sentences, it's been a long day.

 

Here's my php:

<?php
//Get email contents when the server receives the email
$email = file_get_contents('php://stdin');
//$email = "$395";

//Regular expression to find Value of the assignment
$reg_exComp = '/\$(\d+)/';

//Apply the regex to the contents of the email and output to file
preg_match($reg_exComp, $email, $comp);

$i = 1;

//Set the path and filename
$filename = ("C:\\temp\\output".$i.".txt");

       $dir = ("C:\\temp");

//if the file exists renumber the filename and rewrite the variable
while(file_exists($filename)){
     
          $i++;
          $filename = ("C:\\temp\\output".$i.".txt");

      }
    
//create the next highest filename and write to the file.
 $tmpfname = tempnam($dir, "tem");
 $handle = fopen($tmpfname, "a");
 fwrite($handle, $comp[1]);
 copy($tmpfname, $filename);
 fclose($handle);
 unlink($tmpfname);

  
?>

Link to comment
Share on other sites

Looks like I just need to go to bed.  It appears to be an email-related issue.  Either my gmail (that I was using to send test emails from) is limiting how fast I can send emails to one address or hmailserver isn't accepting emails from one address really quickly.  Either way, not a PHP issue.

 

Apologies and thanks for your patience.

Tom

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.