Free Web Hosting Forum
(#1 (permalink))
Old
Junior Member
israelpereiravalverde is on a distinguished road
 
Posts: 5
Join Date: Jan 2012
Default Cron jobs and php path - 02-06-2012, 10:08 AM

Hello, I'm with an big problem using cron jobs with my web system.

I developed my PHP system using MVC design pattern.
The classes are diveded in folders, like that:

public_html >
classes >
dao >
ClassNameDao.php
...
model >
ClassNameBean.php
...
controller >
ClassNameController.php
...
Every class is used by files/pages placed under public_html (like index.php)
So the usual php path is based on "public_html" folder, and some Controller class, for example, requires it's Model and Dao class and the DBConn class that connects to db.
Those classes are included like that:


PHP Code:
include_once 'classes/dao/UserDao.php';
include_once 
'classes/dao/DBConn.php';
include_once 
'classes/model/UserBean.php'

/*If the class I want to include is inside the same folder of the actual class being used (in this example 'classes/controller') I just need to put the name of the class and it's included with no problem.*/
include_once 'UserInfoController.php'

class UserController {

private 
$name, ...;



The problem is: When I use this Controller class for example, with my cron job php file (placed outside my public_html folder) my classes are not called correctly with the relative path in "include_once". I could rewrite the include of ALL my classes to absolute path, but it would took some time and will not be really good, since if I put my web system in another server, I would have to change all the path again.

I also tried to add the public_html folder to php path, but it still shows me errors with the 'include'. Can anyone point me an solution for this problem?
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
Senior Member
Firebirds is on a distinguished road
 
Posts: 252
Join Date: Feb 2012
Default 02-06-2012, 01:27 PM

You have a simple ; problem.

PHP Code:
include_once 'classes/dao/UserDao.php'
include_once 
'classes/dao/DBConn.php'
include_once 
'classes/model/UserBean.php';

/*If the class I want to include is inside the same folder of the actual class being used (in this example 'classes/controller') I just need to put the name of the class and it's included with no problem.*/ 
include_once 'UserInfoController.php';

class 
UserController 

private 
$name, ...; 


That should help


All your problems magically solved.
How to use custom domain. | Account under review? | Can I do this/whatever?
Have a happy magical day
~Firebirds
Reply With Quote
(#3 (permalink))
Old
Junior Member
israelpereiravalverde is on a distinguished road
 
Posts: 5
Join Date: Jan 2012
Default 02-06-2012, 01:29 PM

That is just an example, my real file has the correct syntax.
Reply With Quote
(#4 (permalink))
Old
Senior Member
Firebirds is on a distinguished road
 
Posts: 252
Join Date: Feb 2012
Default 02-06-2012, 01:33 PM

Then read this. Sorry that I can't help you very much, but your problem might be fixed in the comments.
http://www.php.net/manual/en/function.include-once.php


All your problems magically solved.
How to use custom domain. | Account under review? | Can I do this/whatever?
Have a happy magical day
~Firebirds
Reply With Quote
(#5 (permalink))
Old
chanh's Avatar
Administrator
chanh is on a distinguished road
 
Posts: 1,888
Join Date: Dec 2008
Default 02-06-2012, 07:26 PM

read the cron.php in Drupal to see how it is done.
Reply With Quote
Reply

Tags
cron job, include, paths to scripts, php path

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com