Welcome to WebmasterWorld Guest from 50.16.100.60 register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts, Become a Pro Member
 Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

# PHP Server Side Scripting Forum

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

Msg#: 4011113 posted 10:29 pm on Oct 21, 2009 (gmt 0)

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.

eelixduppy

Msg#: 4011113 posted 10:59 pm on Oct 21, 2009 (gmt 0)

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

[php.net...]

miketheman

Msg#: 4011113 posted 11:05 pm on Oct 21, 2009 (gmt 0)

Thank you eelixduppy for replying. Firefox does trigger the script. Is it possible to make integrate php's execution into a scheduled task?

miketheman

Msg#: 4011113 posted 11:06 pm on Oct 21, 2009 (gmt 0)

man windows sucks! this is much easier in ubuntu

miketheman

Msg#: 4011113 posted 11:10 pm on Oct 21, 2009 (gmt 0)

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

miketheman

Msg#: 4011113 posted 11:13 pm on Oct 21, 2009 (gmt 0)

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

eelixduppy

Msg#: 4011113 posted 11:25 pm on Oct 21, 2009 (gmt 0)

So for example:

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

Here's the usage of the executable:
 Usage: php [options] [-f] [--] [args...] php [options] -r [--] [args...] php [options] [-B ] -R [-E ] [--] [args...] php [options] [-B ] -F [-E ] [--] [args...] php [options] -- [args...] php [options] -a -a Run interactively -c ¦ 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 Parse and execute . -h This help -i PHP information -l Syntax check only (lint) -m Show compiled in modules -r Run PHP without using script tags -B Run PHP before processing input lines -R Run PHP for every input line -F Parse and execute for every input line -E Run PHP 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 Load Zend extension . args... Arguments passed to script. Use -- args when first argument starts with - or script is read from stdin --ini Show configuration file names --rf Show information about function . --rc Show information about class . --re Show information about extension . --ri Show configuration for extension .

miketheman

Msg#: 4011113 posted 11:37 pm on Oct 21, 2009 (gmt 0)

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?

miketheman

Msg#: 4011113 posted 11:49 pm on Oct 21, 2009 (gmt 0)

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
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.

miketheman

Msg#: 4011113 posted 12:00 am on Oct 22, 2009 (gmt 0)

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\

miketheman

Msg#: 4011113 posted 12:18 am on Oct 22, 2009 (gmt 0)

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 **
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\

eelixduppy

Msg#: 4011113 posted 2:46 am on Oct 22, 2009 (gmt 0)

 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.

mdinnocenzo

Msg#: 4011113 posted 4:30 am on Oct 22, 2009 (gmt 0)

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

miketheman

Msg#: 4011113 posted 4:48 am on Oct 22, 2009 (gmt 0)

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...]

mdinnocenzo

Msg#: 4011113 posted 1:56 pm on Oct 22, 2009 (gmt 0)

If you do some searching on the switches for the command window you can get that to go away. Good to hear.

franco190453

Msg#: 4011113 posted 6:29 pm on Oct 22, 2009 (gmt 0)

Miketheman:
[webmasterworld.com...]
Regards
Franco

 Global Options: top home search open messages active posts  Tweet

 Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting