dtyw10299 2017-12-05 17:00
浏览 64
已采纳

PHP Cron Manager脚本停止页面加载

I'm trying to make a script that schedules a cron job that sends e-mails on a specific date. I followed this tutorial for making a php cron manager, and it loaded with no problem. But when I tried to make a SSH connection with the script just to see if it would raise any errors, the page stops loading where I place the code, no errors are shown and no error_log file is created anywhere, I really don't understand why the page stops loading.

$crontab = new Ssh2_crontab_manager('xxxxxxxxxxx.xxx', '22', 'xxxxxxx', 'xxxxxxxxxxx');

I only expect it to connect and continue the page or that it at least give me an error that I can search for the solution

Nothing, just a page that's partially loaded and no error, it just stops there.

  • 写回答

1条回答 默认 最新

  • dongyan1841 2017-12-05 21:24
    关注

    Your approach above totally over complicates what you are trying to do. You have a php script you want to run at certain intervals throughout the day, sending a few emails each time to people in your database.

    Obviously I have no idea what your database looks like, but here's a basic concept.

    • Add a column to your email addresses database called sent with default value set to 0
    • Write your php script and in your database query use LIMIT = 10 or whatever to only retrieve a few email addresses each time it runs, use WHERE sent = 0 to only retrieve email addresses you havent sent to yet
    • Then UPDATE each row to SET sent = 1 after the script has run to mark those users as having already been emailed. Include some conditional code so that if there are no more email addresses for that day WHERE sent = 0 then script just exits.

    • Create a cron job to run at your chosen interval which runs your php script and just leave it.

    There is no need to delete the cron job, if there are no emails to send it will just run briefly and quit. The whole point of cron jobs is to automate repetitive tasks, you set once and forget. The filters are flexible enough to give you a lot of control over when they run.

    For example 0 9-17/2 * * 1-5 php /path/to/script.php would run a script every other hour between 0900 and 1700, Monday to Friday

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发