Can CronJobs执行一个包含Javascript的PHP?如果否,任何替代? [英] Can CronJobs execute a php containing Javascript ? If No, Any Alternatives?

查看:265
本文介绍了Can CronJobs执行一个包含Javascript的PHP?如果否,任何替代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要作为cronjob执行的php文件,这个php文件包含一些javascript。

I have php file that is to be executed as cronjob, this php file contains some javascript.

我将解释流程:


  1. Php用于从DB中获取一些数据(A LIST OF URLS)。

  2. 对于每个获取的URL,

  3. 结果从API返回的Obj包含每个网址的数据。

  4. 然后将数据发送回AJAX Call

  1. the Php is used to retrive some data(A LIST OF URLS) from DB.
  2. For each URL Obtained, a Java script API is used.
  3. THe result Obj returned from API contains data for each url.
  4. The data is then sent back to as an AJAX Call for each url to a php file .

这可以通过CRON JOBS实现吗?
OR
有任何方法来计划javascript定期运行,像cron for php?

UPDATE :我可以管理javascript调用API与PHP curl,和cron作业是完全执行。但是我不认为这个问题的正确解决方案可能是Node.Js是解决方案(我没有测试它)。

Can this be implemented Via CRON JOBS ? OR Is there any method to schedule javascript to run periodically, like cron for php?
UPDATE: i could manage the javascript call to API with PHP curl ,And the cron Job is getting executed perfectly. But i dont think it is the correct solution to this question may be Node.Js is the solution(i didnt test it yet).

推荐答案

您不能在Cronjobs中运行Javascript,因为JavaScript是由浏览器运行的。我想你应该看看curp在php中调用api。

You can't run Javascript in Cronjobs because Javascript is ran by browsers. I think you should take a look at curl in php to call an api instead.

http://www.php.net/manual/en/book.curl.php

这篇关于Can CronJobs执行一个包含Javascript的PHP?如果否,任何替代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆