Page 1 of 2
.Bat to run .php page !help!
Posted: Tue Dec 01, 2009 9:19 am
by Goofan
Hi i need some help as i dont understand cron...
i need to make so that everytime the clock hits 00:30 or 01:00 (every 30 min) it will uppdate a datatable and add value into it. it will do this every 30 min. and ive been told to use Cron. I dont understand Cron that much so i cant make the "function" im after. plz help
-Thanks in advance
-Thomas
Re: Cron!!
Posted: Tue Dec 01, 2009 9:34 am
by Grizzzzzzzzzz
might be worth looking at
forums dedicated to Cron
Re: Cron!!
Posted: Tue Dec 01, 2009 9:38 am
by AbraCadaver
Not really PHP because you don't need it here, but here is a solution that can use PHP.
You either edit /etc/crontab or create a crontab for a specific user by doing 'crontab -e'. Then add the following:
Code: Select all
0,30 * * * * /path/to/php /path/to/phpfile.php
Then in /path/to/phpfile.php add the PHP/SQL to do the update.
To skip PHP (assuming you're using MySQL), just add the SQL to the crontab:
Code: Select all
0,30 * * * * mysql -h hostname -u username -ppassword -e "UPDATE mytable SET field = 'value' WHERE something = 'something'"
Re: Cron!!
Posted: Tue Dec 01, 2009 11:06 am
by Goofan
AbraCadaver wrote:Not really PHP because you don't need it here, but here is a solution that can use PHP.
You either edit /etc/crontab or create a crontab for a specific user by doing 'crontab -e'. Then add the following:
Code: Select all
0,30 * * * * /path/to/php /path/to/phpfile.php
Then in /path/to/phpfile.php add the PHP/SQL to do the update.
To skip PHP (assuming you're using MySQL), just add the SQL to the crontab:
Code: Select all
0,30 * * * * mysql -h hostname -u username -ppassword -e "UPDATE mytable SET field = 'value' WHERE something = 'something'"
this part:
-h hostname -u username -p password
is it to connect to the database or something else?
Re: Cron!!
Posted: Tue Dec 01, 2009 11:11 am
by Goofan
and if its the "connect to database shouldnt database.... be in there aswell...
exampel:
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "this"; <-------this as -n this ?
Else would this be correct?
0,30 * * * * mysql -h localhost -u root -p -e "UPDATE konto SET field = 'pengar' WHERE pengar = 'pengar' + 30000"
Re: Cron!!
Posted: Tue Dec 01, 2009 12:09 pm
by AbraCadaver
Goofan wrote:and if its the "connect to database shouldnt database.... be in there aswell...
exampel:
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "this"; <-------this as -n this ?
Else would this be correct?
0,30 * * * * mysql -h localhost -u root -p -e "UPDATE konto SET field = 'pengar' WHERE pengar = 'pengar' + 30000"
Your query doesn't look correct, but I don't know what you're doing so I can't say. You can add the db in the query: UPDATE dbname.konto
Re: Cron!!
Posted: Tue Dec 01, 2009 12:21 pm
by Goofan
found a temporary way to solve this "only got one problem"
ive made so that i run it throught windows scheduled task manager (as this is so far only a home edition(the thing im trying to do))... it runs the script every 30 min.
my only problem is i dont know what to type as it runs "a program" i guess i have to make a .bat file. so i made a .bat file but i still dont know what to type into hte .bat file is it that i should make it to start a .php page with the information (uppdate ..........).
Do u think that would work? im about to try but if u think it wount then tell me

Re: Cron!!
Posted: Tue Dec 01, 2009 12:29 pm
by Goofan
ok so that didnt really work...
i told a bat file this:
content of .bat:
Code: Select all
C:\Program Files\wamp\www\www\Projektarbete\Uppdate_money.php
and i set into Uppdate_money.php:
Code: Select all
<?php
include "database.php";//Fil för databasinställning.
// Build our query
$sql1 = "SELECT * FROM konto";
$result = mysql_query($sql) or die(mysql_error());//Välj all info i tall. //hämtar all info från tabell
while($row = mysql_fetch_array( $result )) //hämtar info från tabell.
{
$pengar = $row['pengar'];
}
$sql="UPDATE konto SET pengar=($pengar + 30000)";//Sätt upp SQL fråga.
?>
see anything i should change or make diffrent?
im not totaly sure about the .bat file if its correct with its content...
-Thanks in advance
-Thomas
Re: .Bat to run .php page !help!
Posted: Tue Dec 01, 2009 12:59 pm
by Goofan
any help appreciated:D
i runned it and well nothing happend...
Re: .Bat to run .php page !help!
Posted: Tue Dec 01, 2009 1:04 pm
by John Cartwright
Hmm.. stick with your other thread (you were headed in the right direction) and this is basically a duplicate.
Re: .Bat to run .php page !help!
Posted: Tue Dec 01, 2009 1:10 pm
by Goofan
which one do u mean and how do u mean? plz help...
Re: .Bat to run .php page !help!
Posted: Tue Dec 01, 2009 1:15 pm
by John Cartwright
What I meant was your best bet is to use cron (linux) or task scheduler (windows) to directly invoke the CLI (Command Line Interface). Not need for a .bat file -- however -- you can find an example
in the manual (scroll down to "Example #9 Batch file to run a command line PHP script (script.bat)").
You simply don't pass the location of the PHP file, since the file itself needs to be interpreted by the PHP engine. Take a look
here on how you would call the your program in CLI.
I suggest you let me know which one of your threads you want me to close, since they are both for the same issue.
Re: .Bat to run .php page !help!
Posted: Tue Dec 01, 2009 1:22 pm
by AbraCadaver
I told myself I was going to leave this thread, but...
First, you need to learn something about what you're doing in PHP and SQL. What you have in the PHP file is never going to work. Second, something like this in the batch file should work:
Code: Select all
c:\path\to\mysql -h localhost -u root -e "UPDATE dbname.konto SET pengar = (pengar + 30000)"
Re: .Bat to run .php page !help!
Posted: Tue Dec 01, 2009 3:23 pm
by Goofan
John Cartwright wrote:What I meant was your best bet is to use cron (linux) or task scheduler (windows) to directly invoke the CLI (Command Line Interface). Not need for a .bat file -- however -- you can find an example
in the manual (scroll down to "Example #9 Batch file to run a command line PHP script (script.bat)").
You simply don't pass the location of the PHP file, since the file itself needs to be interpreted by the PHP engine. Take a look
here on how you would call the your program in CLI.
I suggest you let me know which one of your threads you want me to close, since they are both for the same issue.
besides cant get "any" of the two "idés to work

(.bat idés)
You can close the other one

Re: .Bat to run .php page !help!
Posted: Tue Dec 01, 2009 10:17 pm
by daedalus__
oh now i know why you locked it.
goofan, its daedalus!
where are you at with this? im here to help.