Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running PHP Script with Cronjob

Status
Not open for further replies.

mcmon999

IS-IT--Management
Mar 3, 2005
21
GB
Hi,

I'm attempting to run a PHP script using a Cron job, which imports a csv file into a mysql database.

I initially scheduled them to run within crontab but they were never performed.

I've tested to ensure PHP is set up correctly and that cron is really running.

When I've attempted to run them using the command line:

/usr/bin/php -q /home/linweb01/t/tduk-solutions.co.uk/user/htdocs/response/insert.php

But this doesn't seem to run anything and just moves to the next line.

I've also attempted a simple database connection but this again just moves the cursor.

The php script itself is run fine from the browser and within putty I'm able to run a script that simply displays text to the screen but any sort of database connection and i get no response.

Are there any additional commands i need to included within the PHP script to ensure that this runs?

My Db connections is as follows:

Code:
<?php

	$db_host = "X.X.X.X";
  	$db_name = "DB_name";
    	$db_username = "user";
    	$db_password = "user01";

    $connection = @mysql_pconnect($db_host, $db_username, $db_password) or die("Unable to make connection to database server $db_host");
    @mysql_select_db($db_name, $connection) or die("Unable to find database $db_name");

?>

Let me know if this should be posted in another forum.

Thanks in advance.

 
Hi. As you may be aware, cron is very fussy about variables, and doesn't come with many presets, so you need to replicate as far as possible the environment you run the job in when running it interactively - things like PATH, any specific things (for example in an Oracle environment ORACLE_HOME and ORACLE_SID). Have a look at your environment when running the job interactively and try to include any specifics in your cron-run script.

Some days are diamonds, some days are rocks - make sure most are the former.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top