Question With Cron Jobs..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Howey
Forum Newbie
Posts: 17
Joined: Sun May 16, 2004 5:48 pm
Location: Middle of no where

Question With Cron Jobs..

Post by Howey »

(I hope this is the right area to post =X)

But recently I coded a script for cron jobs.
It works fine when you do it manually, but when I try to make it go through cron jobs, it comes up with this error:
Could not open input file: /home/lincoln/public_html/restock.php?shop=3.
Now yes I know it uses the get function and I was wondering if that's whats screwing it up....

Im sorry I know VERY little on cron jobs :oops:
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

I had a very similar issue. I found that passing a query string was my problem. Remove the variable off of the URL and test it.
User avatar
Howey
Forum Newbie
Posts: 17
Joined: Sun May 16, 2004 5:48 pm
Location: Middle of no where

Yes it works

Post by Howey »

Yes without the variable it works but then my script does nothing :( is there anyway to send the variable through?
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

Most problems with Cron come form invalid permissions. Every user can have cron jobs. They are all different. So if you e.g. manually start a script as root it of course works. If you then start cron as user files might not be read due to wrong set permissions etc.

Might also have to do with path variables that a user have but cron might not.

Another problem might be that cron simply starts your program at the wrong point. Lets say you start a sript with ./sriptname.cgi and all works fine because you are in that directory. If cron starts this file it is not in that directory and variable pathing in that script might not resolve properly.
e.g in perl sripts I usally do something like this:

Code: Select all

chdir "/path-to-script-dir";
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

This may not be the best way to do it but is what I did was this:

What I needed:

Code: Select all

URL =http://test.com/index.php?fun=1
index.php:

Code: Select all

<?php

switch($fun){
 case: 1:
 include('/filename.php');
break;
case 2:
include('filename2.php');
break;
.
..
...
}
?>
What I did:

Code: Select all

URL =http://test.com/index_f1.php
URL =http://test.com/index_f2.php
index_f1.php:

Code: Select all

<?php
include('/filename.php');
exit;
?>
index_f2.php:

Code: Select all

<?php
include('filename2.php');
exit;
?>
This probably isn't the best way to do it but it works in my situation.
User avatar
Howey
Forum Newbie
Posts: 17
Joined: Sun May 16, 2004 5:48 pm
Location: Middle of no where

Post by Howey »

The directory and permissions are fine its just the evil variable,
And as much as I would Like to do it your way, I cant because the whole script basically depends on that variables, it tells which items to get, where to stock the items, how many to stock, ect.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Is it possible to put the variables in a table and when your cron job runs pull the necessary variables from the db?
User avatar
Howey
Forum Newbie
Posts: 17
Joined: Sun May 16, 2004 5:48 pm
Location: Middle of no where

Post by Howey »

hmmm....well I was thinking sense this is all time related would it work just as well, if I had it time oriented?
so it like

Code: Select all

$minutes = date(i);
$true = $minutes/15;

if($true == '1' || $true == '2') &#123;
include('blah.php?shop=2');
&#125;
Would that work you think?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

its worth a try. I don't believe you can pass variables via include() but you can do the following:

Code: Select all

<?php
$user_name = 'james';

include('my_file.php');
?>
my_file.php:

Code: Select all

<?php
echo $user_name;
?>
Let us know how it works for you.
User avatar
Howey
Forum Newbie
Posts: 17
Joined: Sun May 16, 2004 5:48 pm
Location: Middle of no where

Post by Howey »

Alright will do =D thanks for all your help though :D
Post Reply