Hello again
My problem now is that I need to make sendmail command work in the background when calling it from php
(In order not to wait 300mS for each mail when I need to send 20 mails: my web user cannot wait 6 seconds for the page to load)
Unfortunately, multitasking in PHP is not powerful enough for the moment (I don't want to waste resources with a pcntl_fork() on a long program)
So the problem is that I can't right now make sendmail run in the background (with the & at the end of the command line) and pipe it some data.
Because the & makes it work at once in the background, not waiting for stdin.
I mean, this solution doesn't work : popen("/usr/sbin/sendmail -t -i &");
If I fwrite to this pointer, it's too late, sendmail has already gone into the background.
The only solution I found for the moment is to use a sendmail_fork command that I quickly wrote :
==============================================================
#include <stdio.h>
#define SENDMAIL_PATH "/usr/sbin/sendmail"
int main(int argc, char *argv[])
{
char buf[1024];
int i;
int pid;
FILE* p;
strcpy(buf, SENDMAIL_PATH);
for (i=1; i<argc; i++) {
strcat(buf, " ");
strcat(buf, argv[i]);
}
p = popen(buf, "w");
while ((i=fgetc(stdin)) != EOF) {
fputc(i, p);
}
pid = fork();
switch (pid) {
case -1:
printf("fork() error.\n");
return 1;
case 0:
pclose(p);
}
return 0;
}
==============================================================
This program, once compiled, can replace sendmail command.
This is of course a temporary solution.
Is there a good tip to make a program run in the background AFTER all the pipe is received ??
Thanks
Ben