Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    PHP and Cron Jobs. Mass emailer.

    I have about 1500 emails in my database, I have a made a script that will just loop the mail() command for all of them, but I don't want the script to run for over 30 seconds, otherwise it stops. What i would like to do, is run them through a cron job, so the script doesn't need to be up, and i can send them in cycles of a number that i can change online. I have never created a cron job before, and i don't have cpanel. So how can i go about making a php script that will create a cron job, then doing it. Can i get some code examples here? Thanks alot.

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    php probably wont be able to create the cron job for you since it would need elevated permissions to do so (unless you are lucky and apache or php appear in /usr/lib/cron/cron.allow).

    if you have shell access use crontab to create the cron entry and simply point it at your php file ...

    /usr/local/php -q -f /home/user/scripts/cronjob.php

    + remember to chmod a+x the cronjob.php
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You might need your host to start your crontab. Would email/phone them, as most don't like you using mass email from their servers

  • #4
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    How do things like Invsion Power Board or VBulleting send out there mass emails? They are using cron jobs right? I want to do something like that.

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You mean the main company sites, or peoples personal sites? Personal sites won't use cron jobs, the main sites more likely will

  • #6
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    They might use cron jobs but they also might just use an open SMTP connection. If you use mail() repeatedly the result will be very slow, for every e-mail the system opens a connection, sends the e-mail and then closes the connection.

    With an open SMTP connection, the server opens the connection, sends every single e-mail through the same connection and then closes it.

    Is this what you want, or do you specifically want to use a Cron job?

  • #7
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    Im really just looking to do whatever way the have it running through Invision Power Board. You can mass email without a smtp connection, so im assuming it uses mail().

  • #8
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if invision is anything like vbulletin.. 'scheduled tasks' are not run via cron... they seem to be run when a user goes to a page and if it has reached a certain time it will run (I have not verified this but it wouldn't surprise me). I would say to use a *real* cronjob since then you are able to manage the email in a queue and contain the flow (listen to firepages).

  • #9
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If the prroblem is that it is taking two long to complete the script then you can change the execution time for that script.

    like this set_time_limit(3000) ;
    the only prroblem is that if you are not outputting anything to the browser then the browser will look like the page has crashed. so you would need to print something to the screen every 20 seconds or so.

    hope this helps

  • #10
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    the problem is, i just don't want to make the admin sit there on the email page until it finishes. I want them to click send, then be able to do other things and know that the emails are being sent.

  • #11
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by thesavior
    the problem is, i just don't want to make the admin sit there on the email page until it finishes. I want them to click send, then be able to do other things and know that the emails are being sent.
    that is why you use a cronjob, it will be able to 'run in the background' ..

  • #12
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    haha, so we are back to the beggining. Can i get some code to set up a cronjob to do this?

  • #13
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by thesavior
    haha, so we are back to the beggining. Can i get some code to set up a cronjob to do this?
    No, ask your sysadmin or do it via cpanel or whatever

  • #14
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    haha, no because im making a forum system, and if i release it, i want it to set it up, not manually.

  • #15
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    then you will have to write a scheduler that will be able to limit resources.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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