Cron job in php

Links for php scripts

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 2
Joined: Mon Jan 09, 2012 4:38 am

Cron job in php

Postby sumeetbiswal » Tue Feb 28, 2012 1:39 am

Hi All,
I am a php developer.I am doing a project which requires some functionality to run automatically in server.So i tried cron job in php.i am very new to cron job in php.I have no control panel password to do it.
i want to write some code in php for cron job and upload it in server throgh FTP.
i want a file runs in every 5 mins every day.
my server API is CGI script.
please anybody help me how to do it and say me the step for cron job for running a php file .

New php-forum User
New php-forum User
Posts: 21
Joined: Thu Apr 12, 2012 8:05 am

Re: Cron job in php

Postby FishBird » Thu Apr 12, 2012 10:53 am

You needto set a cronjob on the server itself. You cannot start a script just by itself.

To get it working without using real cronjobs, you can store in your databse when your cron last runned, and let a user activate it:

Code: Select all

$last_runned = $db->query("SELECT `last_run` FROM `lastrunned` LIMIT 1");
$last_runned = $db->fetch(2);
if( $last_runned['last_run'] + 300 < time() ){
 $db->query("UPDATE `lastrunned` SET `last_run` = ?", array( $time()) );

Something like that.

Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest