SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist chiphunt1's Avatar
    Join Date
    Oct 2003
    Location
    louisville, ky
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    exec php script in background

    I created a PHP script that builds emails dynamically for anywhere from 200-400 customers depending on what customers the user selects. Each email has a market report and associated pricing. Every customer has different pricing schemes, so that is why it is dynamic. I use PHP mailer from sourceforge to build and send the emails. It has been working great. It takes a long time for the script to finish execution, so I didn't want the user to sit there and wait or run the risk of the browser timing out. I decided to execute the script from the command line and make it a background process then send the user to a confirmation page. This is the command I used and it has been working flawlessly for months:

    $ip = $_SERVER['REMOTE_ADDR'];
    exec("/usr/local/bin/php -q sendMarketReport.php Value1 $ip > /dev/null &");
    echo " <script>window.location=\"confirmation.php\"</script>";

    The problem is we had a new security package installed and it does not allow apache to execute commands, so my exec statement won't work anymore. Any ideas? I know I can set the time out for php much higher but I don't want to do that. I want the user to have an immediate confirmation.
    Calm down -- it's only ones and zeroes

  2. #2
    SitePoint Wizard holmescreek's Avatar
    Join Date
    Mar 2001
    Location
    Northwest Florida
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put your script somewhere like /somefolder/myscript.php

    When you want to do a mailing, copy myscript.php to /somefolder/myscripttemp.php

    set up a cron tab to run /somefolder/myscripttemp.php then delete it so it only runs once.
    intragenesis, llc professional web & graphic design

  3. #3
    SitePoint Evangelist chiphunt1's Avatar
    Join Date
    Oct 2003
    Location
    louisville, ky
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is fine if I'm the one running the script, but this is a web app built for a client who has no idea about cron tab or linux or anything like that. They fill out a webedit textarea for the market report and click submit, then check all the clients they want to send the email to and click send button the form submits to next page which calls the exec function and then the browser redirects to the confirmation page. The client in no way ever accesses our server, nor do I want them to. I thought about setting up a cron job to send the email once per week because that is about how often the report goes out, but it's compeletely random when they decide to make or send the report. They can make the report and save it and never send it. The report shows up on the website as well. Thanks for your input.
    Calm down -- it's only ones and zeroes

  4. #4
    SitePoint Wizard holmescreek's Avatar
    Join Date
    Mar 2001
    Location
    Northwest Florida
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The point I was making, is have your cron job check for a file in the temporary folder, say, every 15 minutes, if a file is found then process it.

    When your customer is given the option to "send now" have the script temporarly copy the script over into the temp folder where the cron will pick it up, execute, then delete it from the temp folder.

    Hope this clarifies my thoughts.

    Good Luck!
    intragenesis, llc professional web & graphic design


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •