Jump to content

Recommended Posts

I am trying to find out a way to run a script on local host at 10 minutes intervals using a cron. I don't want to buy a server just to practice how to run crons.

 

I'm doing a simple addition on the database which is Energy + 1 = Energy thus causing the Energy field in the database to go up by 1 every 10 minutes.

 

I had this tutorial that i was following through:

http://drupal.org/node/31506

 

But it doesn't allow php files to be run and im on vista that tutorial doesn't refer to same OS as half the stuff it mentions is either not there or in a completely different place to where it says.. so i was wondering how can i do crons without paying for a server..

 

If i cannot... are there other alternatives to doing what i need done (it needs to happen even if the user is logged out)?

Link to comment
https://forums.phpfreaks.com/topic/73226-php-with-a-cron-job/
Share on other sites

You can run any PHP script by using the PHP runtime.  On Windows machines, it would be php.exe located in your PHP install directory.  On *nix machines, it's typically /usr/local/bin/php

 

You can first test out your script by running it from the command line (assuming your script is called dbupdate.php):  php.exe dbupdate.php.  If you script provides any output, you should see it on the command line.

 

I'm not sure about Vista, but in XP you could use the scheduler (found in the control panel) to schedule your db update program "php.exe dbupdate.php > c:\dbupdate.out"

 

(The '>' tells the shell to place the output of the script in dbupdate.out since you won't see anything if it's run from the scheduler)

 

Here's how to do it in Vista: http://technet.microsoft.com/en-us/windowsvista/aa906020.aspx

Link to comment
https://forums.phpfreaks.com/topic/73226-php-with-a-cron-job/#findComment-369443
Share on other sites

You can run any PHP script by using the PHP runtime.  On Windows machines, it would be php.exe located in your PHP install directory.  On *nix machines, it's typically /usr/local/bin/php

 

You can first test out your script by running it from the command line (assuming your script is called dbupdate.php):  php.exe dbupdate.php.  If you script provides any output, you should see it on the command line.

 

I'm not sure about Vista, but in XP you could use the scheduler (found in the control panel) to schedule your db update program "php.exe dbupdate.php > c:\dbupdate.out"

 

(The '>' tells the shell to place the output of the script in dbupdate.out since you won't see anything if it's run from the scheduler)

 

Here's how to do it in Vista: http://technet.microsoft.com/en-us/windowsvista/aa906020.aspx

 

Thanks for the link,

 

but totally lost me at the first part =/

 

using the PHP runtime - may i ask what your referring to here.. this is something i have not heard of before..

Link to comment
https://forums.phpfreaks.com/topic/73226-php-with-a-cron-job/#findComment-369469
Share on other sites

PHP is a program like any other.  When you request a php webpage, your webserver tells the PHP interpreter (can be called the runtime, ie. php.exe) to take the interpret the file you asked for and then gives the output to the client.  When you run a cron, you tell the computer to start the php interpreter and bypass the browser completely.

 

There are three different interpreters, php (the main one), php-cgi and php-win (for windows machines).  You can use php or php-win, I don't think it matters. 

Link to comment
https://forums.phpfreaks.com/topic/73226-php-with-a-cron-job/#findComment-369472
Share on other sites

test.php

 

then i put :

 

test.exe ?

 

Not quite.  PHP programs do not need to be compiled, i.e. translated into machine language -- if you open a .exe file in notepad, that's what the compiled version of a program looks like (it's all garbage to you, but Windows knows how to read it and execute it).

 

For programming languages such as C or Java, first you would have to translate your programs into machine language (i.e. compile them), and only then, you can run them.

 

PHP programs are basically interpreted on the fly (during runtime).  The PHP interpreter (i.e. php.exe) is the program that immediately translates your programs into machine language as it is executing it.

 

This is probably way too much info already, so I'll cut to the chase:

 

You need to find you php.exe on your system (probably under C:\PHP\bin\php.exe) and run it like I indicated in the post above:

 

php.exe test.php

 

This tells the PHP interpreter that you would like to execute your test.php program.

Link to comment
https://forums.phpfreaks.com/topic/73226-php-with-a-cron-job/#findComment-369525
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.