dongtaihui5131 2013-02-08 10:22
浏览 35

Zend Framework 2自动化php程序

What's the best way for execute automated php procedures in Zend Framework 2?

I want to schedule a task to operate in the Database (mysql), but it doesn't interact with any HTTP call, i.e. only a server side execution.

I would like the procedute was a defined in my framework module, it's posible?

If itsn't posible defined in my module, how I can do it outside?

  • 写回答

1条回答 默认 最新

  • doushen2154 2013-02-08 12:10
    关注

    I am not sure if you need to do any work in PHP or not, but if you don't, you can make use of MySQL's Event Scheduler. This will allow you to run scheduled jobs within your database. Read more about the syntax for creating such events here. Here is an example:

    CREATE EVENT some_event
    ON SCHEDULE AT 12:34:00 EVERY DAY
    DO
    UPDATE my_schema.my_table SET my_column = my_column + 1;
    

    I didn't test it, so hopefully it works.

    Alternatively, you can make a cronjob on your server. Most shared hosting providers also allow you to do this. If you are not using shared hosting, you could have the cronjob run something like this:

    mysql -u username -p password -e "UPDATE my_schema.my_table SET my_column = my_column + 1";
    

    Again, not tested, but it should point you in the right direction.

    Another option is to use a cronjob together with cURL such that when the cronjob is run, an URL is requested.

    curl http://yourdomain.com/yourtask

    Then in Zend Framework, you could have a yourtask route or just use module, controller and action in the URL. Then you would send off the database query from PHP and Zend Framework.

    You could also just have a standalone PHP script somewhere else that is called by cURL. Or better yet, by PHP directly. Then it does not have to be available to the world.

    As you see, you have quite a few options. Choose the one that is right in your case. We don't have enough details to make this choice.

    评论

报告相同问题?

悬赏问题

  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False