Jump to content

cron jobs trouble


Ashstyx

Recommended Posts

hello im having trouble with this code im not sure if you can help me but ima paste the code here and i will see what people say, the problem is this:

 

PHP Fatal error: require(): Failed opening required '../class/class_db_mysql.php' (include_path='.:') in /var/www/vhosts/dclxvi.co.uk/httpdocs/crons/cron_day.php on line 6

 

my code is this:

 

<?php

include_once ('../Global/config.php');

global $_CONFIG;

if($_GET['code'] != $_CONFIG['code']) { die(""); }

define("MONO_ON", 1);

require "../class/class_db_{$_CONFIG['driver']}.php";

$db=new database;

$db->configure($_CONFIG['hostname'],

$_CONFIG['username'],

$_CONFIG['password'],

$_CONFIG['database'],

$_CONFIG['persistent']);

$db->connect();

$c=$db->connection_id;

$db->query("UPDATE fedjail set fed_days=fed_days-1");

$q=$db->query("SELECT * FROM fedjail WHERE fed_days=0");

$ids=array();

while($r=$db->fetch_row($q))

{

$ids[]=$r['fed_userid'];

}

if(count($ids) > 0)

{

$db->query("UPDATE users SET fedjail=0 WHERE userid IN(".implode(",", $ids).")");

}

$db->query("DELETE FROM fedjail WHERE fed_days=0");

$db->query("UPDATE users SET daysingang=daysingang+1 WHERE gang > 0");

$db->query("UPDATE users SET daysold=daysold+1, boxes_opened=0");

$db->query("UPDATE users SET mailban=mailban-1 WHERE mailban > 0");

$db->query("UPDATE users SET donatordays=donatordays-1 WHERE donatordays > 0");

$db->query("UPDATE users SET cdays=cdays-1 WHERE course > 0");

$db->query("UPDATE users SET bankmoney=bankmoney+(bankmoney/50) where bankmoney>0");

$db->query("UPDATE users SET cybermoney=cybermoney+(cybermoney/100*7) where cybermoney>0");

$q=$db->query("SELECT * FROM users WHERE cdays=0 AND course > 0");

while($r=$db->fetch_row($q))

{

$cd=$db->query("SELECT * FROM courses WHERE crID={$r['course']}");

$coud=$db->fetch_row($cd);

$userid=$r['userid'];

$db->query("INSERT INTO coursesdone VALUES({$r['userid']},{$r['course']})");

$upd="";

$ev="";

if($coud['crSTR'] > 0)

{

$upd.=",us.strength=us.strength+{$coud['crSTR']}";

$ev.=", {$coud['crSTR']} strength";

}

if($coud['crGUARD'] > 0)

{

$upd.=",us.guard=us.guard+{$coud['crGUARD']}";

$ev.=", {$coud['crGUARD']} guard";

}

if($coud['crLABOUR'] > 0)

{

$upd.=",us.labour=us.labour+{$coud['crLABOUR']}";

$ev.=", {$coud['crLABOUR']} labour";

}

if($coud['crAGIL'] > 0)

{

$upd.=",us.agility=us.agility+{$coud['crAGIL']}";

$ev.=", {$coud['crAGIL']} agility";

}

if($coud['crIQ'] > 0)

{

$upd.=",us.IQ=us.IQ+{$coud['crIQ']}";

$ev.=", {$coud['crIQ']} IQ";

}

$ev=substr($ev,1);

if ($upd) {

$db->query("UPDATE users u LEFT JOIN userstats us ON u.userid=us.userid SET us.userid=us.userid $upd WHERE u.userid=$userid");

}

$db->query("INSERT INTO events VALUES('',$userid,unix_timestamp(),0,'Congratulations, you completed the {$coud['crNAME']} and gained $ev!')");

}

$db->query("UPDATE users SET course=0 WHERE cdays=0");

$db->query("TRUNCATE TABLE `votes`");

?>

Link to comment
Share on other sites

The error is very clear:

 

PHP Fatal error: require(): Failed opening required '../class/class_db_mysql.php' (include_path='.:') in /var/www/vhosts/dclxvi.co.uk/httpdocs/crons/cron_day.php on line 6

 

The file it's trying to include could not be opened.  Check that it exists, and that it has permissions that allow the user apache is running as, to get to it and open it.

Link to comment
Share on other sites

ive looked and its there in the correct place and in the config file "driver" is correct

 

<?php

$_CONFIG = array(

'hostname' => 'localhost',

'username' => '******',

'password' => '******',

'database' => 'game_db',

'persistent' => 0,

'driver' => 'mysql',

'code' => 'b828de441d44ec5bcd01e5339da0b4c5',

'define_code' => 'ec7be771f2854a058de3c36d515f7580',

);

?>

Link to comment
Share on other sites

ok im a noob when it comes to crons its the only trouble ive had with my text based game, i bought the code and ive learnt alot since i started but everywhere i go i cant find the help i need on the crons,

 

basicly i need explaining to me like im a 10yr old lol

Link to comment
Share on other sites

Nope, your a noob when it comes to a lot of things related to computer operations.

.. denotes the directory above the current directory - these are relative paths - which yer script is using (look at the requires and includes)

when they say to use an absolute path, they mean to use the full pathname, which should start at the root file structure

/home/xxxx/www/include.php

 

if you need help in getting the directory, try using this

<?php echo getcwd(); ?>

 

than update your cron job script with absolute paths

Link to comment
Share on other sites

An absolute path always starts with a '/'.  That specifies the top of the directory tree.

 

Let's say you have a file system structure like this:

 

/mysite/admin
            /game
            /library/
                       config

 

Now in your config directory you have a file that has database credentials you need to include in other scripts.  The file is named db.inc.php. Then the absolute path to that script is:

 

/mysite/library/config/db.inc.php

 

Then there are "relative paths".  If the path does not start with the '/' it requires the software to figure out where a file is "relative to the 'current working directory'".  Here's some examples of relative paths that could be used:

 

library/config/db.inc.php

 

Lets say you have a script in the game directory named index.php, and you wanted to try and include the db.inc.php.

 

include( '../config/db.inc.php');

 

The problem with this, is that it depends on the the setting of the current working directory.  When you are cronning php scripts, you are not in the web environment, so things that might work in that context, and the current working directory settings, will often not work because command line php is not operating as part of a web server.  You can write a little wrapper script that sets the current working directory (using cd /directory) or do that before the call to php -f in the cron line, however, in general it is best if your php scripts are using absolute paths. 

 

You can do some searching and googling and reading up on using the __FILE__ constant as the basis of calculating a "basepath" that you can then add to other relative path variables, to tranform them into absolute paths at runtime.  The use of relative paths like '../../etc' is error prone, confusing, and experienced developers don't do it, whether it's a cron'd script or scripts run in the apache environment.

Link to comment
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.