如何测试像WAMP这样的本地服务器中的cron作业?

时间:2021-12-18 17:35:37

How to test a cron job in Local Server like WAMP?

如何测试像WAMP这样的本地服务器中的cron作业?

10 个解决方案

#1


13  

Windows doesn't have Cron (it is the main task scheduling program for Linux systems). The Windows version for that is the Task Scheduler. This question recommends using the at command.

Windows没有Cron(它是Linux系统的主要任务调度程序)。 Windows版本是任务计划程序。此问题建议使用at命令。

So that Cron doesn't have anything to do with the Apache, Mysql, PHP setup I don't think it is possible to reliably test the cronjobs you created for the Linux Cron in windows (maybe with Cygwin).

因此,Cron与Apache,Mysql,PHP设置没有任何关系,我认为不可能可靠地测试您在Windows中为Linux Cron创建的cronjobs(可能使用Cygwin)。

#2


7  

You can create a html page and open it on browser. The javascript setInterval function will call for specified periods.

您可以创建一个html页面并在浏览器上打开它。 javascript setInterval函数将调用指定的句点。

Following is the code to do this. Specify your interval (5000 eg. which runs every 5sec)

以下是执行此操作的代码。指定您的间隔(例如,每5秒运行一次)

<html>
<head>
    <title>Cron</title>
</head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<body>
<h1>Cron page</h1>
<script type="text/javascript">
    setInterval(function(){
        $.get('http://localhost/test/test.php', function(data) {
            console.log(data);
         });
    }, 5000);
</script>
</body>
</html>

Note: To avoid CORS you should call ajax from same host or allow CORS from server side.

注意:要避免CORS,您应该从同一主机调用ajax或从服务器端允许CORS。

#3


5  

you can run your script directly from URL, means if you want to run cron_test.php script from cron setting and you want to test the result for the same then you can directly run this file from localhost like http://localhost/XXXX/cron_test.php.

您可以直接从URL运行脚本,意味着如果您想从cron设置运行cron_test.php脚本并且您想测试结果,那么您可以直接从localhost运行此文件,如http:// localhost / XXXX / cron_test.php。

#4


3  

Install cron (yes, it is available for Windows).

安装cron(是的,它适用于Windows)。

I wouldn't want to do that on Windows though. You'd probably be better off grabbing a copy of VirtualBox and creating something that better resembles your production environment to do your development in.

我不想在Windows上这样做。你可能最好抓住VirtualBox的副本并创建一些更适合你的生产环境的东西来进行开发。

#5


2  

Simply run the job from the command line. It is the job that you're wanting to test, not cron itself. If you need to have it execute at periodic intervals to simulate cron, then use the Windows "Scheduled Tasks" facility

只需从命令行运行作业即可。这是你想要测试的工作,而不是cron本身。如果需要定期执行以模拟cron,则使用Windows“计划任务”工具

#6


2  

You can run this:

你可以运行这个:

set_time_limit(0);
ignore_user_abort(true);
while (1)
{
    //your code here....
    sleep($timetowait);
}

You can close your browser the script will continue

您可以关闭浏览器,脚本将继续

set_time_limit(0); make your script work with no time limitation

参数或者set_time_limit(0);让你的脚本工作没有时间限制

sleep($timetowait); determine the time to wait before executing the next loop of while()

睡眠($ timetowait);确定在执行while()的下一个循环之前等待的时间

ignore_user_abort(true); let the script continue even if browser is closed

ignore_user_abort(真);即使浏览器关闭,也要让脚本继续运行

while(1) is an infinite loop, so this will never stop until you exit wamp.

while(1)是一个无限循环,所以在你退出wamp之前永远不会停止。

#7


1  

You can just cron your jobs in windows environment with just one line. I have almost spent my 5 hours so i want to share with other is make a task.

您只需一行即可在Windows环境中完成工作。我几乎花了5个小时,所以我想与其他人分享是一项任务。

  • In program give php.exe path, with my installation it is c:\wamp\bin\php\php5.3.5\php.exe.
  • 在程序中给出php.exe路径,我的安装是c:\ wamp \ bin \ php \ php5.3.5 \ php.exe。

  • Second you have to put the file absolute path, which you want to run. -f c:\wamp\www\foo\foo.php in the argument
  • 其次,您必须放置要运行的文件绝对路径。参数中的-f c:\ wamp \ www \ foo \ foo.php

So that's complete. There is no need for installing anything.

这样就完成了。无需安装任何东西。

#8


0  

<meta http-equiv="refresh" content="0; url=http://localhost/myproject/cron.php" />

set up a meta referesh immediately: content = 0 every 5 seconds: content = 5

立即设置元referesh:content = 0每5秒:content = 5

#9


-1  

What do you mean by "a cron job"? On a lot of websites there is a special page like "cron.php" which is hit periodically, normally like so:

你的“cron job”是什么意思?在很多网站上都有一个特殊的页面,比如“cron.php”会定期点击,通常是这样的:

0 * * * * wget http://example.org/cron.php

In which case you just need to manually hit your cron php file to simulate the behaviour.

在这种情况下,您只需手动命中您的cron php文件来模拟行为。

#10


-1  

Try this commnad

试试这个commnad

<?php

echo exec('0 13 * * * D:\wamp\bin\php -f D:\wamp\www\be.php');

?>

#1


13  

Windows doesn't have Cron (it is the main task scheduling program for Linux systems). The Windows version for that is the Task Scheduler. This question recommends using the at command.

Windows没有Cron(它是Linux系统的主要任务调度程序)。 Windows版本是任务计划程序。此问题建议使用at命令。

So that Cron doesn't have anything to do with the Apache, Mysql, PHP setup I don't think it is possible to reliably test the cronjobs you created for the Linux Cron in windows (maybe with Cygwin).

因此,Cron与Apache,Mysql,PHP设置没有任何关系,我认为不可能可靠地测试您在Windows中为Linux Cron创建的cronjobs(可能使用Cygwin)。

#2


7  

You can create a html page and open it on browser. The javascript setInterval function will call for specified periods.

您可以创建一个html页面并在浏览器上打开它。 javascript setInterval函数将调用指定的句点。

Following is the code to do this. Specify your interval (5000 eg. which runs every 5sec)

以下是执行此操作的代码。指定您的间隔(例如,每5秒运行一次)

<html>
<head>
    <title>Cron</title>
</head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<body>
<h1>Cron page</h1>
<script type="text/javascript">
    setInterval(function(){
        $.get('http://localhost/test/test.php', function(data) {
            console.log(data);
         });
    }, 5000);
</script>
</body>
</html>

Note: To avoid CORS you should call ajax from same host or allow CORS from server side.

注意:要避免CORS,您应该从同一主机调用ajax或从服务器端允许CORS。

#3


5  

you can run your script directly from URL, means if you want to run cron_test.php script from cron setting and you want to test the result for the same then you can directly run this file from localhost like http://localhost/XXXX/cron_test.php.

您可以直接从URL运行脚本,意味着如果您想从cron设置运行cron_test.php脚本并且您想测试结果,那么您可以直接从localhost运行此文件,如http:// localhost / XXXX / cron_test.php。

#4


3  

Install cron (yes, it is available for Windows).

安装cron(是的,它适用于Windows)。

I wouldn't want to do that on Windows though. You'd probably be better off grabbing a copy of VirtualBox and creating something that better resembles your production environment to do your development in.

我不想在Windows上这样做。你可能最好抓住VirtualBox的副本并创建一些更适合你的生产环境的东西来进行开发。

#5


2  

Simply run the job from the command line. It is the job that you're wanting to test, not cron itself. If you need to have it execute at periodic intervals to simulate cron, then use the Windows "Scheduled Tasks" facility

只需从命令行运行作业即可。这是你想要测试的工作,而不是cron本身。如果需要定期执行以模拟cron,则使用Windows“计划任务”工具

#6


2  

You can run this:

你可以运行这个:

set_time_limit(0);
ignore_user_abort(true);
while (1)
{
    //your code here....
    sleep($timetowait);
}

You can close your browser the script will continue

您可以关闭浏览器,脚本将继续

set_time_limit(0); make your script work with no time limitation

参数或者set_time_limit(0);让你的脚本工作没有时间限制

sleep($timetowait); determine the time to wait before executing the next loop of while()

睡眠($ timetowait);确定在执行while()的下一个循环之前等待的时间

ignore_user_abort(true); let the script continue even if browser is closed

ignore_user_abort(真);即使浏览器关闭,也要让脚本继续运行

while(1) is an infinite loop, so this will never stop until you exit wamp.

while(1)是一个无限循环,所以在你退出wamp之前永远不会停止。

#7


1  

You can just cron your jobs in windows environment with just one line. I have almost spent my 5 hours so i want to share with other is make a task.

您只需一行即可在Windows环境中完成工作。我几乎花了5个小时,所以我想与其他人分享是一项任务。

  • In program give php.exe path, with my installation it is c:\wamp\bin\php\php5.3.5\php.exe.
  • 在程序中给出php.exe路径,我的安装是c:\ wamp \ bin \ php \ php5.3.5 \ php.exe。

  • Second you have to put the file absolute path, which you want to run. -f c:\wamp\www\foo\foo.php in the argument
  • 其次,您必须放置要运行的文件绝对路径。参数中的-f c:\ wamp \ www \ foo \ foo.php

So that's complete. There is no need for installing anything.

这样就完成了。无需安装任何东西。

#8


0  

<meta http-equiv="refresh" content="0; url=http://localhost/myproject/cron.php" />

set up a meta referesh immediately: content = 0 every 5 seconds: content = 5

立即设置元referesh:content = 0每5秒:content = 5

#9


-1  

What do you mean by "a cron job"? On a lot of websites there is a special page like "cron.php" which is hit periodically, normally like so:

你的“cron job”是什么意思?在很多网站上都有一个特殊的页面,比如“cron.php”会定期点击,通常是这样的:

0 * * * * wget http://example.org/cron.php

In which case you just need to manually hit your cron php file to simulate the behaviour.

在这种情况下,您只需手动命中您的cron php文件来模拟行为。

#10


-1  

Try this commnad

试试这个commnad

<?php

echo exec('0 13 * * * D:\wamp\bin\php -f D:\wamp\www\be.php');

?>