简体   繁体   English

运行来自cron作业的包含javascript的php文件

[英]Run a php file contain javascript from cron job

I tried many online methods people have suggested and still not reached a solution 我尝试了人们建议的许多在线方法,但仍未找到解决方案

i need to run a php file that contain javascript from cronjob 我需要运行包含来自cronjob的javascript的php文件

For now, I can not do it through PHP 目前,我无法通过PHP做到这一点

If anyone has an idea I'd love to read 如果有人有想法我很想读

You will probably have to trigger it through a browser. 您可能必须通过浏览器触发它。 Get a computer to open the URL via the cron tab (or some other timed device... I know you can do it through Automator/AppleScript on a Mac). 让计算机通过cron选项卡(或其他定时设备……打开URL)。我知道您可以通过Mac上的Automator / AppleScript来打开它。

How I do it: I split the job in to tasks. 我该怎么做:我将工作分为多个任务。

Task 1: Execute Javascript 任务1:执行JavaScript

Javascript would require a browser to run. Javascript需要浏览器才能运行。 In this respect you can try casperjs/phantomjs. 在这方面,您可以尝试casperjs / phantomjs。 You can create aa cronjob for this easily. 您可以为此轻松创建一个cronjob。 Please check: Running a casper.js script from cron 请检查: 从cron运行casper.js脚本

Task 2: Deliver results to PHP 任务2:将结果传递给PHP

I assume that you take the results of the JS and use it in the PHP. 我假设您获取了JS的结果并在PHP中使用了它。 So JSON can do the job. 因此,JSON可以胜任。 At the end of the first task output to a file. 在第一个任务的末尾输出到文件。 In this task, read it using file_get_contents. 在此任务中,使用file_get_contents读取它。

Task 3: PHP Cron 任务3:PHP Cron

It is obvious :) 这很明显 :)

Sure that there are better, easier and simpler solutions. 确保有更好,更简单的解决方案。 I am a newbie also here, but this method all my problems for a similar work. 我也是这里的新手,但是这种方法解决了我所有类似工作的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM