homepage Welcome to WebmasterWorld Guest from 54.163.70.249
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP to run at set intervals - Help!
asusplay




msg:4421300
 11:52 am on Feb 24, 2012 (gmt 0)

Hi there
I need some help trying to deal with some external xml files.

At the moment I load the contents of xml files via simplexml, create a temporary table in the database with mysql and output the contents in different ways. The temporary table is created so that different values can be calculated from the values given in the xml files (for comparisons etc). However this temporary table is created every time a user requests the page and the xml files take some time to load which is dependent on the external servers which less than ideal.

I modified the script so that instead of creating a temporary table, it creates a real table in the database, First it checks if the table exists, drops it, and creates a new one when the script is run. it all works perfectly for my requirements.

Now the problem comes when I want this to run every 5 minutes (as an example). I tried to set up a cron jon (I'm on shared hosting) but even through the time was set up right and the command line was set to path of the file from the errors I was getting that it doesn't actually run the php file, but it's more of a command of some sort...I'm no programmer and no nothing about these things.

How can I get my php file to run itself at a set interval?

 

g1smd




msg:4421305
 12:04 pm on Feb 24, 2012 (gmt 0)

Cronjob, but be careful with the syntax.

asusplay




msg:4421317
 1:43 pm on Feb 24, 2012 (gmt 0)

That's just the problem, I have absolutely no idea about the syntax and nothing seems to work :(

I am trying

"/home/username/public_html/folder/includes/create-table.php >> /dev/null" in the command line. I have also set permissions to 777 otherwise i get a permission denied error. When it executes the file I get the error messages on the email it sends out. It is as if it cannot read php but is reading in unix? I am no programmer, maybe I'm way off the mark here.

line 1: ?: No such file or directory
line 2: =: command not found
line 3: require_once: command not found
line 4: require_once: command not found
line 5: require_once: command not found
line 8: =DROP table if exists SiteMonitor: command not found
line 9: syntax error near unexpected token `$drop'
line 9: `$dropTable=mysql_query($drop);'

asusplay




msg:4421365
 3:19 pm on Feb 24, 2012 (gmt 0)

I got it working!

I had to add <? #!/usr/local/bin/php -q ?> at the beginning of the file and change all the paths to relative.

and on the commans line i ammended it to

php /home/username/public_html/folder/includes/create-table.php

g1smd




msg:4421377
 3:44 pm on Feb 24, 2012 (gmt 0)

Glad you got it. I was going to log in to a server later today and copy the syntax I use as I couldn't remember it rightaway.

rocknbil




msg:4421393
 4:38 pm on Feb 24, 2012 (gmt 0)

....so that instead of creating a temporary table, it creates a real table in the database


These are pretty much identical, mysql handles creates and drops the temporary tables automatically. :-)

/home/username/public_html/folder/includes/....


For future reference within your scripts you may want to do something like this:

$_SERVER['DOCUMENT_ROOT'] . "/includes...."

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved