dongnanman9093 2012-10-26 20:29
浏览 39
已采纳

有可能使用ajax,jquery页面与cron?

what my page do is:

  1. download an array from different server (first.php)
  2. php script parse values
  3. parsed values are sent with ajax call
  4. on the next (ajax called) page (second.php) there are some mysql queries
  5. if values pass condition, values are written to database

.... So, when I run my first.php.. it loads second.php, everything's fine.. but what I want to know if it is possible to let it make by cron?

If not, what should I do? Thanks.

  • 写回答

3条回答 默认 最新

  • dousi7579 2012-10-26 20:36
    关注

    There are certain things you need to understand in this regard.

    The first is that PHP can be run as either a web server module or as a standalone executable. When you run it as a web server module, you open it from the browser, all related web technologies (html/css/js) etc get parsed and work in unison.

    When you run it from command line using cron like say /usr/bin/php mywebpage.php then the php executable DOES NOT parse/understand the other web technologies and so your page will fail.

    There are two workarounds for this:

    1. Rewrite only those web-enabled parts so that the ajax/js stuff gets handled by PHP. Basically rule of the thumb is that if you are running a CLI php script, it should contain ONLY core PHP. This is the preferred way. You will need to move the ajax calls to inside the same file and just make it a single execution flow like any regular program.

    2. If for some reason you cannot do the above, you can try something like this: /path/to/browser http://mysite/mywebpage.php. Here what you are doing is, you are running a browser executable and then calling the webpage URL. This way the page is being executed within the browser's environment and it will be able to parse and understand the ajax/js calls.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问