We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49846
    • 22 Posts
    Hello,

    I have a snippet that finds all the active users in my db (approx 457 users) and then compare extended fields to a criteria. Those who matches the criteria, an email gets send to them via ModMailer.

    In my localhost development, all the users who matches the criteria (45 users out of 457) has the email sent to them successfully, however, when running the code on my server, the foreach activeuser loop stops before looping through all users. As a result, only 9 users get sent the email.

    Does anyone have any idea why this is the case between the localhost development and the development on my server? Thanks
      • 44922
      • 131 Posts
      I wonder whether this could be PHP or Apache timeout settings which are different on your web server to your local host. I am no expert on this, it just suggests if the code works fine on development server, and you are running the same website instance, that some server configuration might cause the issue.
        • 3749
        • 24,544 Posts
        The default PHP timeout is 30 seconds on almost all servers, so there's a good chance that lancipoos is correct.

        You can try adding this line inside the loop:

        set_time_limit();


        That resets the clock, but many servers ignore it.

        You might take a look at the MandrillX class. It will send the emails through Mandrill (which lets you send 12,000 emails per month for free). It's not very difficult to set up and would avoid the timeout (plus give you lots of record keeping and bounce information at Mandrill).

        BTW, I think the Notify extra does almost exactly what you want (and has the option to use Mandrill). When coupled with Subscribe, it also handles registration of the users and sends them an unsubscribe link.

        If you register at Bob's Guides, you can see it in action.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 49846
          • 22 Posts
          Thank you lancipoos and BobRay for your response. I have fixed the problem, it was a time-out on the server. I had the following error in my log: mod_fcgid: read data timeout in 31 seconds

          After googling, I changed the IPCCommTimeout from 30 to a higher value and it seems to have fixed the problem.

          With regard to your suggestion bob with the set_time_limit();. I had that included in the loop, however it was being ignored.

          Thank you guys anyway!