简体   繁体   English

通过Windows Apache模块运行PHP计划的任务

[英]Running PHP scheduled task through Windows Apache Module

Okay, so we have this site that we took over from a previous firm...PHP, Zend Framework, MySQL etc. 好的,所以我们有了这个站点,该站点由以前的公司接管... PHP,Zend Framework,MySQL等。

It's an interesting site in that they utilize a CMS that's external (they manage some data like forums, user subscription, etc.) 这是一个有趣的网站,因为他们利用外部CMS(它们管理一些数据,例如论坛,用户订阅等)。

So there's a library that communicates via web service calls from PHP to the CMS, and then from JavaScript it calls the code which returns JSON data (which is then manipulated into HTML/CSS). 因此,存在一个库,该库通过Web服务调用从PHP到CMS进行通信,然后通过JavaScript调用返回JSON数据的代码(然后将其处理为HTML / CSS)。

We need a scheduled task that runs daily. 我们需要每天运行的计划任务。 Its job is to get users from this CMS, iterate through them and check xxx amount of fields. 它的工作是从此CMS获取用户,对其进行遍历并检查xxx字段数量。 Based upon the number of fields populated, if 80% or greater is populated, they're eligible to be a featured user. 根据填充的字段数,如果填充80%或更多,则有资格成为精选用户。

And, in our database, I have 2 fields (isFeatured and featuredIndex). 并且,在我们的数据库中,我有2个字段(isFeatured和FeaturedIndex)。 isFeatured being a flag, featuredIndex since a featured user will either be #1, #2, or #3. isFeatured是一个标志,featureIndex,因为有特征的用户将是#1,#2或#3。

Either way, our dev environment is Windows + PHP5 + Apache (with PHP running as an Apache module, and not CGI). 无论哪种方式,我们的开发环境都是Windows + PHP5 + Apache(PHP作为Apache模块而不是CGI运行)。

I'm thinking the easiest approach is to write a PHP page that will be in the web root, which will only have permissions so it can be run as a scheduled task. 我在想最简单的方法是编写一个将位于Web根目录中的PHP页面,该页面仅具有权限,因此可以作为计划任务运行。 What do you guys think? 你们有什么感想?

My challenge is I need to test this locally (suggestions?). 我的挑战是我需要在本地测试(建议?)。 The staging and production environments are LAMP setups, fwiw. 过渡和生产环境是LAMP设置。 So, I guess my questions are the following: 因此,我想我的问题如下:

  1. Is this a good way of handling this issue? 这是处理此问题的好方法吗? Ie a scheduled task which utilizes the existing framework (which relies on this 3rd party CMS with web service communications and Zend Framework) 即利用现有框架的计划任务(该框架依赖于具有Web服务通信和Zend Framework的此第三方CMS)
  2. How do I write this script so it can run both on Windows and Linux (PHP)? 如何编写此脚本,使其可以在Windows和Linux(PHP)上运行?
  3. And how do I schedule this script to run on a daily basis on Windows and Linux (since it's web based). 以及如何安排该脚本每天在Windows和Linux上运行(因为它是基于Web的)。

Thanks all, -Steve 谢谢大家,-史蒂夫

If you used Popular Frameworks there is a big chance that you could find a solution. 如果您使用Popular Frameworks,则很有可能找到解决方案。 Its ok that you give us such Informations but without any code example we cannot even if we would. 可以的,您可以给我们这样的信息,但是如果没有任何代码示例,我们将无法做到。

All, 所有,

What it looks like I should do is create the script and have accessible via the web, then have a cron job call wget. 我应该做的是创建脚本并可以通过Web进行访问,然后进行cron作业调用wget。 Apparently wget is available via Windows, and I can use it in addition to the scheduled tasks on Windows to have it run on Windows, and for Linux have crontab + wget. 显然,wget可通过Windows获得,并且我可以在Windows上安排的任务之外使用它,以使其在Windows上运行,而对于Linux,则具有crontab + wget。

-Steve -史蒂夫

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

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