Welcome to WebmasterWorld Guest from 54.226.62.251

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP to run at set intervals - Help!

     

asusplay

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

5+ Year Member



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

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Cronjob, but be careful with the syntax.

asusplay

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

5+ Year Member



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

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

5+ Year Member



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

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

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

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



....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...."
 

Featured Threads

Hot Threads This Week

Hot Threads This Month