Don't ask to ask, just ask | |
PerlMonks |
Sharing STDIN after forkby Bod (Parson) |
on Feb 13, 2022 at 02:09 UTC ( [id://11141358]=perlquestion: print w/replies, xml ) | Need Help?? |
Bod has asked for the wisdom of the Perl Monks concerning the following question: I am trying to create an email sending system that can be driven directly from our CRM. The current system which this will replace works fine but involves copying and pasting blocks of text with addresses and HTML code for emails. So I want something easier to use and less error-prone. The script we currently use calls itself with a query string parameter set so it tracks the sending of the emails. The problem is that it can behave strangely if refreshed or called again whilst an email is still sending. So, for the replacement, I am trying to fork a process. One process will send the emails and the other will load a webpage that will periodically check the progress through AJAX calls. The progress will be stored in a DB table. I am getting strange behaviour which I think is because sometimes one process grabs STDIN and other times the other process gets it.
Within the require "incl/common.pl"; file, the %data hash is populated from the $ENV{'QUERY_STRING'} variable and STDIN. This file also connects the database. Sometimes $data{'mail'} is passed to the template and sometimes it is written to the test file. I have had problems with fork before where I have made the database connection after the fork. Then one process has ended and closed the database connection on the other process. For that reason, here I am connecting after the fork. I don't really want to play with the require (it is nasty but works) as a lot of other code relies on it. I have rarely used fork so...am I along the right lines in how I am doing this with fork or is there a better way?
Back to
Seekers of Perl Wisdom
|
|