如何制作适用于Windows和Unix的php自动化后台脚本? [英] how to make a php automation background script for Windows and Unix?

查看:77
本文介绍了如何制作适用于Windows和Unix的php自动化后台脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,可以创建较大图像的缩略图,并且可以正常工作,问题在于它位于页面的开头,可以查看两个图像,并且据我所知,每次有人访问该页面时,脚本都将运行.这似乎表现不佳.

I have a script that creates thumbnails of larger images and it works fine, the problem is that it is placed at the beginning of the page where both images are viewed and to my understanding would run every time someone visits the page. This doesn't seem very performant.

我希望脚本具有自己的页面,并且以某种方式检测到何时将更大的图像添加到了它扫描的目录中,然后开始工作.

I would rather the script have its own page and somehow detected when more large images had been added to the directory it scans and go to work then.

我该如何进行设置或以某种方式进行改进?

How would i go about setting this up or improving it in someway?

发现了这个,不确定它是如何工作的.什么是$ cmd:

found this, not sure how it works. what is $cmd:

  /*I combined several efforts in this topic into one function: 
This will execute $cmd in the background (no cmd window) 
without PHP waiting for it to finish, on both Windows and Unix.*/
    function execInBackground($cmd) { 
        if (substr(php_uname(), 0, 7) == "Windows"){ 
            pclose(popen("start /B ". $cmd, "r"));  
        } 
        else { 
            exec($cmd . " > /dev/null &");   
        } 
    } 

推荐答案

创建时基:也许(如果您具有Shell访问权限),则可以创建"Cron作业":

Time base creation : Perhaps (if you have a shell access), you can create a "Cron job" :

在''/etc/crond.d/''中创建这样的文件:

In ''/etc/crond.d/'' Create a file like this :

0 6-18 * * *    root    /path/to/your/script.php >> /dev/null 2>&1

它将从6.00到18.00每小时执行一次.

It will be execute every hour from 6.00 to 18.00.

有关更多详细信息,请参见: http://en.wikipedia.org/wiki/Cron

See : http://en.wikipedia.org/wiki/Cron for more details.

自动创建: 如果您有上传过程",请在上传后简单地放置缩略图生成器".

Automatic Creation : If you have an "upload procedure", put simply the "Thumbnail generator" after uploading.

挂钩创建: 确实,这取决于您用于在目录中添加新图像的过程.

Hook Creation : Indeed, it depend of the procedure you use to add new images in your directory.

也许,您也可以在更新目录后制作钩子以执行脚本.

Perhaps, you can also make a hook to execute the script after updating the dir.

但是我认为基于时间(cron)的第一个解决方案最容易实现.

But I think the first solution based on time (cron) is the most easy to implement.

这篇关于如何制作适用于Windows和Unix的php自动化后台脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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