dtcd27183 2015-06-06 09:08
浏览 64
已采纳

使用PHP和Apache创建一个cron作业

I have Apache running on Debian with PHP 5.4.
PHP-cli is installed.
My directory structure for the web project is:

 - /myproject
     - /src
         - /controller
             - getProviders.php
         - /model
         - /public
         - ClassLoader.php

I want to create a cron job to execute getProviders.php every 5 minutes. This is as far as I have come:
*/5 * * * * /usr/bin/php /var/www/myproject/src/controller/getProviders.php

It doesn't work because I have a require_once in getProviders.php requiring ClassLoader.php, but he can't find it.
require_once "../ClassLoader.php"

getProviders.php works when executed via URL.

I'm not new to PHP development, but new at configuring the server around it. What do I have to do to make it work. I'm guessing I have to set the include path, but I have no idea to what exactly.

Thanks in advance for your help.

  • 写回答

3条回答 默认 最新

  • douchengjue9892 2015-06-06 09:13
    关注

    To make sure the require_once will always work, you could use dirname(__FILE__) + the path relative to the getProviders.php

    In your case this would be:

    require_once(dirname(__FILE__)."/../ClassLoader.php");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 求大神教题,这个代码和讲解思路都怎么写呀,完全卡住了
  • ¥15 基于ffmpeg 编码成yuv420p nv12的问题
  • ¥15 python随机森林对两个excel表格读取,shap报错
  • ¥15 基于STM32心率血氧监测(OLED显示)相关代码运行成功后烧录成功OLED显示屏不显示的原因是什么
  • ¥100 X轴为分离变量(因子变量),如何控制X轴每个分类变量的长度。
  • ¥30 求给定范围的全体素数p的(p-2)/p的连乘积值
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗