Wednesday, January 3, 2018

In PHP How to Set Up A Windows Scheduled Task bachelor of information technology (bit) external degree university of colombo school of computing

Set Up A Windows Scheduled Task


Warning: The following assumes you have administrative access to the Windows server where b2Evolution is served from and that the Task Scheduler service is enabled. These instructions are valid for Windows Server 2000 and 2003. They will probably work for Windows NT with some minor changes, but really - shouldn’t you just ! Also, if you frequently have to call your child/cousin/uncle/brother/grandmother to get you out of trouble with your PC, DO NOT try this. Call your child/cousin/uncle/brother/grandmother now and ask them to do it for you, before you get in to trouble. You can wait patiently in the kitchen baking chocolate chip cookies to offer as a reward for a job well done. And as always, you should back up any important data before beginning.
So, you want to set your  Scheduler to run on a regular basis using your Windows server, eh? Follow along as we explore the magic of the Windows Task Scheduler service.

First Things First

First you’ll need to know exactly where this script resides on your system. If you don’t know already (maybe you should call that child/cousin/uncle/brother/grandmother now?), you can find it by clicking Start -> Search -> For Files and Folders from the task bar and entering "cron_exec.php" as the search criteria. These instructions will assume you found it at:
C:\Inetpub\wwwroot\blogs\cron\cron_exec.php
Next we need to know where PHP is installed. You definitely have it installed already if your server is serving out delicious b2Evolution pages, so fret not. You can do that search thing again, this time entering "php.exe" as the search term. These instructions will assume you found it at:
C:\PHP\php.exe
PHP comes in many different flavors: Apache module, CGI module, Command Line module (CLI), etc. The preferred version to use here is the CLI version. Lets test it. Click Start -> Run… from the task bar and enter "cmd". This will open the Windows command prompt. At the command line (it should look like ‘'’C:\>”’) enter the full path to your php.exe file followed by " -v" (that’s [space][minus][lowercase v]) and hit Enter.
It should look something like this:
Shell
C:\PHP\php.exe -v
And return something like this:
Shell
PHP 5.1.2 (cli) (builtJan 11 2006 16:40:00)
  Copyright (c1997-2006 The PHP Group
  Zend Engine v2.1.0Copyright (c1998-2006 Zend Technologies
If you’re lucky, you’ll find that "cli" designation after the version number. If not (maybe you see a bunch of HTML, or just no CLI designation) this may still work but you should try to find the CLI executable of your PHP installation. You can check the PHP website (http://www.php.net) for details on your specific version of PHP.
For the purposes of this tutorial, we’ll assume that every thing worked peachy and that you’re using the CLI version.

Hello World

Now lets make sure that cron_exec.php script will play nicely with your php.exe file. Go back to your command prompt and enter:
Shell
C:\PHP\php.exe "C:\Inetpub\wwwroot\blogs\cron\cron_exec.php"

And it should result in the simple message:
Shell
There is no task to execute yet.
If you see any other messages or if you just get a bunch of HTML, read through these and correct what ever is wrong. If you continue to have trouble try posting a question in the b2Evolution forums http://forums.b2evolution.net/. For instance, the first time around I got this:
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x
html1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
        <head>
                <title>b2evolution is not configured yet</title>
        </head>
<body>
        <div style="background-color:#fee; border: 1px solid red; text-align:cen
ter; ">
                <p>This is b2evolution version 1.8-beta.</p>
                <p><strong>You cannot use the application before you finish conf
iguration and installation.</strong></p>
                <div style="font-weight:bold; color:red;">Base configuration is
not done! (see /conf/_basic_config.php)</div>
                <p>Please use the installer to finish your configuration/install
ation now.</p>
                <p>On most installations, the installer will probably be either
<a href="install/index.php">here</a> or <a href="../install/index.php">here</a>.
.. (but I can't be sure since I have no config info available! :P)</p>
        </div>
</body>
</html>
I fixed the problem by going through the installer, then ran the command again and got the expected message.

Putting It All Together

The final step will be to set the script to run automagically. For starters, we need to get out our Task Scheduler. From the task bar, click Start -> Programs -> Accessories -> System Tools -> Scheduled Tasks. You may not have any scheduled tasks defined yet, in which case you’ll see only an icon to add a scheduled task, but ‘’don’t click it!'’ I know it’s tempting, but that opens one of those fancy "wizards" and we would rather do things the unwizard way, thank you very much. A numbered list will walk us through the next steps. I give you - Mr. Numbered List!
  1. Right-click on an empty spot in the Scheduled Task window and select New -> Scheduled Task (Also accessible via File -> New -> Scheduled Task)
  2. Name the new task (How about "Bill"? He looks like a Bill, doesn’t he? "Mr. B. Evolution, II" It sounds so regal.)
  3. Double-click the new task to open the properties window (or ‘’File -> Properties'’)
  4. Under the Task tab, enter the same command that you used to test the script above. For instance, I would enter: C:\PHP\php.exe "C:\Inetpub\wwwroot\blogs\cron\cron_exec.php"
  5. Go to the Schedule tab and enter when and how often the task should run. The schedule defaults to run once daily and should be fine for basic usage, but feel free to tweak as needed.
  6. The rest of the fields can be left as-is, unless you’re an ace and know what you’re doing.
  7. Click OK and we’re done!

Wrapping Up

You’ll probably want to run the task once to make sure everything goes OK. First, change the view of the Scheduled Task window to show all details (View -> Details). Next, right click the task and select Run (or File -> Run). Watch the Last Run Time column - when it changes from Never to todays date the task has finished running. Now look in the Last Result column. You should see the code "0x0", which means the task completed successfully. If you see any other code, click Advanced -> View Log in the menu bar and look for any errors reported for your task. Fix any problems and test again until you are successful.
That should do it!


Be Prepared Today For Your Feature!!!

bachelor of information technology (bit) external degree university of colombo school of computing

Home visits Individual / Group / Online classes in English / Sinhala / Tamil. Sample Projects/Assignments Exam Papers, Tutorials, Notes and Answers will we provided.
CALL +94 777 33 7279 | EMAIL  ITCLASSSL@GMAIL.COM | SKYPE  ITCLASSSL