5 Replies - 1470 Views - Last Post: 19 March 2012 - 07:46 PM

#1 lupekid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-March 12

CronJobs

Posted 19 March 2012 - 07:09 PM

How Do I Use Cronjobs??
Anyone Need Help Trying To Do This Code


<?php

include "Safe.php"; 

$sql = mysql_query("SELECT * FROM users WHERE id='" .mysql_real_escape_string($_SESSION['user_id']). "'")

or die(mysql_error());

$row = mysql_fetch_object($sql);

$name = htmlspecialchars($row->name);

$energy = htmlspecialchars($row->energy);

$rank = htmlspecialchars($row->rank);

$energy_loss = array("1","5","10","15","30");


$sql = mysql_query("UPDATE users SET energy=energy+'100' AND energy != '$energy_inc[$rank];'");

$query = mysql_query($sql) or die(mysql_error());

?>


Is This A Good Question/Topic? 0
  • +

Replies To: CronJobs

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5388
  • View blog
  • Posts: 27,384
  • Joined: 10-May 07

Re: CronJobs

Posted 19 March 2012 - 07:11 PM

cronjobs are part of the linux/unix hosting environment. You don't use them in php code. It's the equivalent of the Windows Task Scheduler
Was This Post Helpful? 1
  • +
  • -

#3 lupekid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-March 12

Re: CronJobs

Posted 19 March 2012 - 07:17 PM

View Postno2pencil, on 19 March 2012 - 07:11 PM, said:

cronjobs are part of the linux/unix hosting environment. You don't use them in php code. It's the equivalent of the Windows Task Scheduler

So how do i do this then?
I Wana add like for example 100 energy to every user on sql.
how can i do that? thanks for the reply
Was This Post Helpful? 0
  • +
  • -

#4 lupekid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-March 12

Re: CronJobs

Posted 19 March 2012 - 07:24 PM

Can i do this?

*/30 * * * * /the/script/place/script.php
wont that work? or nah
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3099
  • View blog
  • Posts: 10,885
  • Joined: 08-August 08

Re: CronJobs

Posted 19 March 2012 - 07:43 PM

I have no knowledge of any case where using cron jobs to run PHP scripts is not bad design. As far as I know it is always possible to achieve the same goals without resorting to a cron job.
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5388
  • View blog
  • Posts: 27,384
  • Joined: 10-May 07

Re: CronJobs

Posted 19 March 2012 - 07:46 PM

View Postlupekid, on 19 March 2012 - 10:24 PM, said:

Can i do this?

*/30 * * * * /the/script/place/script.php
wont that work? or nah

Erm, without knowing what you want to do... I mean we're really taking some assumptions here.

1.) that your hosting has granted you access to the shell to install crontabs
2.) that the shell can execute php scripts
3.) that the reference php script performs an action that will be useful on a repeated basis.

If the page doesn't work, then running it every half hour doesn't really accomplish anything.

Also cronjobs have nothing to do with php coding, so I am moving this topic to web servers & hosting where this discussion is actually ontopic.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1