题
我需要一个 PHP 脚本作为 Windows 中的服务运行。
是否有捷径可寻?
解决方案
您必须使用SC.EXE。访问 http://support.microsoft.com/kb/251192 了解详情。 然后,只需使用的php.exe yourscriptname作为命令行的服务来执行
其他提示
如果你不介意让你的手脏了一点CSHARP,这里是有壳的应用程序,是一个Windows服务的URL。它规定执行批处理文件(即脚本)每隔多少秒的计时器。如果你的脚本执行任务,然后退出只会工作。 (标记为社区维基,因为这不是我的代码。我在这里复制所有代码的情况下,所链接的网站开始在未来的死。)
HTTP://www.akchauhan。 COM /创建 - 窗口服务到时间表的PHP脚本的执行/
这里的链接的文章中提到的代码。
C#的服务:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;
namespace MyNewService
{
public partial class MyNewService : ServiceBase
{
private Timer syncTimer = null;
public MyNewService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
syncTimer = new Timer();
this.syncTimer.Interval = 180000;
this.syncTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.syncTimer_Tick);
syncTimer.Enabled = true;
}
protected override void OnStop()
{
syncTimer.Enabled = false;
}
private void syncTimer_Tick(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(@"C:\xampp\htdocs\task.bat");
}
}
}
在必要的批处理文件:
@echo off
cd\
set path=C:\xampp\php;
cd "C:\xampp\htdocs"
php import.php
exit
这可能是一个问题 https://superuser.com/ 或者 https://serverfault.com/
这可能会提供一些有关服务的帮助http://support.microsoft.com/kb/251192
我已经有一段时间没有使用 Windows 了,但您也许可以设置一个批处理文件作为服务运行。
不隶属于 StackOverflow