Jump to content

Bosque Bill

New Members
  • Content Count

    4
  • Joined

  • Last visited

    Never

Community Reputation

0 Neutral

About Bosque Bill

  • Rank
    Newbie

Profile Information

  • Gender
    Not Telling
  1. A tip from another forum gave me the idea of passing the Session ID via arguments (I'd previously failed passing the ID via URL.) By passing the ID, you avoid all the problems with complex variables/arguments. I tried variations of using SID without success and finally stumbled upon this technique. For the parent script: $pass_id = escapeshellarg(session_id()); $command = "/usr/bin/php /home/mydir/send-mail-fork.php {$pass_id} > /dev/null 2>&1 &"; exec($command); For the child script: <?php session_id($argv[1]); session_start(); Hope this helps someone else trying to use Sessions in a background script.
  2. Oops, the final redirection I showed in my example above actually didn't allow background operation. This works: "> /dev/null 2>&1 &" This didn't: "> /dev/null &" You may have to test what works with your server. For clarity the above line should have been: $command = "/usr/bin/php /home/[mydir]/send-mail-fork.php {$pass_subject} {$pass_message} {$pass_footer} > /dev/null 2>&1 &"; Hope this helps someone else.
  3. Oh, that was so close to working, however, the white space in my strings were splitting the string into separate arguments. Still, you pointed me in the right direction. I searched and found shell_quote which isn't PHP, but I then found escapeshellarg(). Perfect! This is what I ended up with: $pass_subject = escapeshellarg($_SESSION['subject']); $pass_message = escapeshellarg($_SESSION['message']); $pass_footer = escapeshellarg($_SESSION['footer']); $command = "/usr/bin/php /home/[mydir]/send-mail-fork.php {$pass_subject} {$pass_message} {$pass_footer} 2> /dev/null &"; $status = exec($command); Thanks for your help.
  4. I have a working set of scripts that allows a non-technical client to maintain a mailing list. The scripts use php sessions to store things like $subject, $message, etc. That works. I now need to sleep my script to satisfy the server number-of-emails-per-time requirements, so want to fork off the actually mail sending to a background script using either exec() or shell_exec() so the client won't have to wonder why the page isn't loading. This too works, however, the script I forked off doesn't seem to be able to access my session variables. I tried passing the session id as part of the filename, but that breaks things. Can I use php sessions to pass these variables? Or do I need to stuff them into a db table in the calling script and pull them out in the forked script?
×
×
  • 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.