How to run a Php task periodically on Windows server?

Posted on 2012-08-21
Last Modified: 2012-12-05

I need to to run a Php task periodically on Windows server.
Preferably the Php script would write the task in the Task Manager.

Thank you
Question by:starhu
    LVL 49

    Accepted Solution

    Use the scheduler (AT) to schedule the task.
    Preferably the Php script would write the task in the Task Manager.

    Not sure what you mean by this Task Manager is a monitoring utility that gives information on what apps / services are running on a computer and what their resource utilisation is. Applications executed will appear their by default - you don't write to it.

    With the at command you can either get it to run your script directly or use it to run a batch file. (Assumes relevant scripts are in E:\temp - change as required - you need to give full paths to all scripts because the scheduler will not start in the folder where they are stored unless you configure it to).

    php e:\temp\phpscript.php

    Open in new window

    $test ="This is a test";
    file_put_contents('e:\temp\testoutput.txt', $test);

    Open in new window

    Either create from command line or through GUI
    AT command from command line (assumes bat file is in E:\temp
    at 9:00am /every:tuesday e:\temp\dophpscript.bat

    Open in new window

    LVL 34

    Expert Comment

    Just use task scheduler to execute:
    c:\php\php.exe c:\path\to\your\script.php

    And replace the first part with the appropriate path to the php.exe on your system.

    Author Comment

    As you may have already noticed it instead of "Task Manager" I meant "Task Scheduler".

    Sorry for this.
    LVL 49

    Expert Comment

    by:Julian Hansen
    See my post above and let me know if that answers your question.

    Author Comment

    I have sent the post to my colleague: he will try it tomorrow, thank you very much

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Learn about cloud computing and its benefits for small business owners.
    Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now