Welcome to WebmasterWorld Guest from 54.166.122.69

Forum Moderators: coopster & jatar k

creating a scheduled task to run a php script just like cron job

make a cron job

   
10:29 pm on Oct 21, 2009 (gmt 0)

5+ Year Member



I'm having issues making a cron job.
I'm trying to run a script I've written in php. If I go to the page,in a browser, it runs the script. I was able to make a scheduled task and it does successfully execute, but then it opens up a firefox browser.

What I really hope to achieve is a scheduled task that will run in the background without opening a firefox browser or one that will at least close the browser it opens.

In my scheduled tasks run line I have:
C:\PROGRA~1\MOZILL~1\firefox.exe http://www.example.com/tester.php

The line under START IN:
C:\PROGRA~1\MOZILL~1

Any suggestions I greatly appreciate. Thank you anyone and everyone.

10:59 pm on Oct 21, 2009 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



You cannot have firefox "execute" the code, but rather you have to use the php.exe interpreter itself to execute the code.

[php.net...]

11:05 pm on Oct 21, 2009 (gmt 0)

5+ Year Member



Thank you eelixduppy for replying. Firefox does trigger the script. Is it possible to make integrate php's execution into a scheduled task?
11:06 pm on Oct 21, 2009 (gmt 0)

5+ Year Member



man windows sucks! this is much easier in ubuntu
11:10 pm on Oct 21, 2009 (gmt 0)

5+ Year Member



eelixduppy..how would I run php from the command line in windows?

Is it the same as
Start -> Run -> cmd -> ?

would I enter cd C:\location\php.exe

11:13 pm on Oct 21, 2009 (gmt 0)

5+ Year Member



I read the php manual on shell command.
I did
Start -> Run -> php -v
This opened a terminal and closed it...was I missing something or isn't it suppose to let me know if it is CLI or CGI
11:25 pm on Oct 21, 2009 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



You have to add the command in the task...

So for example:


C:\php\php.exe -f path\to\your\script.php

Here's the usage of the executable:


Usage: php [options] [-f] <file> [--] [args...]
php [options] -r <code> [--] [args...]
php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
php [options] -- [args...]
php [options] -a

-a Run interactively
-c <path>¦<file> Look for php.ini file in this directory
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-f <file> Parse and execute <file>.
-h This help
-i PHP information
-l Syntax check only (lint)
-m Show compiled in modules
-r <code> Run PHP <code> without using script tags <?..?>
-B <begin_code> Run PHP <begin_code> before processing input lines
-R <code> Run PHP <code> for every input line
-F <file> Parse and execute <file> for every input line
-E <end_code> Run PHP <end_code> after processing all input lines
-H Hide any passed arguments from external tools.
-s Output HTML syntax highlighted source.
-v Version number
-w Output source with stripped comments and whitespace.
-z <file> Load Zend extension <file>.

args... Arguments passed to script. Use -- args when first argument
starts with - or script is read from stdin

--ini Show configuration file names

--rf <name> Show information about function <name>.
--rc <name> Show information about class <name>.
--re <name> Show information about extension <name>.
--ri <name> Show configuration for extension <name>.

11:37 pm on Oct 21, 2009 (gmt 0)

5+ Year Member



could it be spacing as an issue?

I tried in the scheduled task run line:
"C:\Program Files\PHP\php.exe - f C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\posting\tester.php"

After I click Apply Then OK. Then in the scheduled tasks window which displays all the scheduled tasks, I'd right click the paticular cron job and click run and it will say Could Not Start?

11:49 pm on Oct 21, 2009 (gmt 0)

5+ Year Member



AWESOME!

I was able to run the php script from the cmd line
For Others Information:
1. I moved my cron script (cron.php) to the PHP folder on my system.
2. Then go to START -> RUN -> cmd (this opens the terminal)
3. Then I entered: cd C:\Program Files\PHP\ (this moves commands to the specified directory
4. Then I took your advice eelixduppy, enter: php -f tester.php
5. This successfully runs the script provided that your cron script is updated appropriately with the correct directories (ex. instead of writing to /postings/here.txt, change it C:/Program Files/Apache /full path/here.txt)

Now Step 6. I'm going to try to add your last bits in the scheduled task section and will post results.

12:00 am on Oct 22, 2009 (gmt 0)

5+ Year Member



hmmm...it still wont start the scheduled task.

I tried these in combinations:
RUN: "C:\Program Files\PHP\php.exe -f C:\Program Files\PHP\tester.php"
START IN: C:\Program Files\PHP\

RUN: "C:\Program Files\PHP\php -f tester.php"
START IN: C:\Program Files\PHP\php

RUN: "C:\Program Files\PHP\php.exe -f tester.php"
START IN: C:\Program Files\PHP\

Still nothing.....please help, my hair is falling out as I type.

12:18 am on Oct 22, 2009 (gmt 0)

5+ Year Member



I Think This is the problem. In the error logs for Scheduled Tasks:

I see this:

"php.job" (tester.php) 10/21/2009 5:15:32 PM ** ERROR **
Unable to start task.
The specific error is:
0x80070002: The system cannot find the file specified.
Try using the Task page Browse button to locate the application.

Is it the formatting of the run? Currently Set:
RUN: "C:\Program Files\PHP\php.exe -f C:\Program Files\PHP\tester.php"
START IN: C:\Program Files\PHP\

2:46 am on Oct 22, 2009 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member




Try using the Task page Browse button to locate the application.

Seems it cannot find php.exe. Have you tried using the browse method instead of typing it in manually. Perhaps you are missing something.

4:30 am on Oct 22, 2009 (gmt 0)

5+ Year Member



try adding the location of the php.exe and the *.php file that you want to run to the environment variable for your system path. This way no matter how you call the files your system will be able to find them

Thats why START > RUN > CMD can find cmd.exe

you will have to restart the system after adding the location to the path

4:48 am on Oct 22, 2009 (gmt 0)

5+ Year Member



Thank you eelixduppy and mdinnocenzo,

I was able to remedy the problem as follows:

To make the scheduled task...because for some reason the php.exe wasn't executing the script, I tested it in regular cmd prompt and it worked.

I then created a .bat file and enter this in it run the execution through cmd:
cd C:\Program Files\PHP & php -f cron\icrawl.php & exit

what this is cd -> go to this directory -> php call -> the cron script -> exit

This allows a scheduled task to run now and execute a cron script. I guess the only downside to it is that a cmd window pops open and closes immediately when the scheduled task is automatically carried out, but it doesn't take any focus away from my current screen.

Hope this helps anyone else who stumble upon it. I also got more details from this thread:
[webmasterworld.com...]

1:56 pm on Oct 22, 2009 (gmt 0)

5+ Year Member



If you do some searching on the switches for the command window you can get that to go away. Good to hear.
6:29 pm on Oct 22, 2009 (gmt 0)

5+ Year Member



Miketheman:
This might help you ->
[webmasterworld.com...]
Regards
Franco
 

Featured Threads

Hot Threads This Week

Hot Threads This Month