/    Sign up×
Community /Pin to ProfileBookmark

Good morning everyone
plz i want to know how to create a cron job using php function and also how to stop this cron from working using php…
all that i need is to create a cron job using php and when the administrator press send -> the cron will be execute
and when he press stop -> the cron will be deleted from cpanel

note that: the administrator does not have an access to the cpanel and also if he has .. he can not deal with it.

[COLOR=”Red”]so can anyone have a function to creeate a cron job using php? and also stop it?[/COLOR]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@zahidrafApr 29.2009 — Cron job is not the linx code

those are Linux file which execute some script that can either php or any other lanugage

There are two ways to make a cron job

one is cpanel and other one is Linux shell.

LG GC 900 Viewty 2 exposed
Copy linkTweet thisAlerts:
@john_zakariaauthorApr 29.2009 — Try this:

http://www.underwaterdesign.com/2006/06/php_create_a_cron_job_with_php.php[/QUOTE]


[code=php]
<?
crontab_set('*','*','*','*','*');
function crontab_set ($min, $hour, $monthDay, $monthNum, $weekDay)
{
$command = "$min $hour $monthDay $monthNum $weekDay /usr/local/bin/php -f /home/egypthol/public_html/snd2.php";


//echo $command;
$cron_file = "Feed_cron";

// check for cron/Feed_cron file. If it doesn't exist create it.
// you must create the file from the browser to associate the proper group
if (file_exists($cron_file))
{ // if it exists, write new command


$open = fopen($cron_file, "w"); // This overwrites current line
fwrite($open, $command);
fclose($open);

// this will reinstate your Cron job

exec("crontab /home/egypthol/public_html/cron/Feed_cron") or die ("Error");

}
else

{ // if it Doesn't exist, Create it then write command
touch($cron_file); // create the file, Directory "cron" must be writeable
chmod($cron_file, 0777); // make new file writeable

$open = fopen($cron_file, "w");
fwrite($open, $command);
fclose($open);

// start the cron job!
exec("crontab /home/egypthol/public_html/cron/Feed_cron")
or die ("Error");



}

}
?>
[/code]


this is my code... and it makes the file Feed_cron and make inside it the commad

[COLOR="Red"][SIZE="5"]

but there is an error in the[B] exec [/B]line coz when the page is loaded the die message ("error") appears.. so i found that the error is in the execute line[/SIZE]
[/COLOR]


could u plz help me in solving this problem
Copy linkTweet thisAlerts:
@MindzaiApr 29.2009 — Are you running this on a unix machine?
Copy linkTweet thisAlerts:
@john_zakariaauthorApr 29.2009 — plz take a look on these 2 links:

http://www.egyptholidaytours.com/cron/cron.php --> this is the page that creates the cron job file and when wirting exec it shows the die error

http://www.egyptholidaytours.com/cron/test.php --> shows the sever details

plz i need help in solving this problem
×

Success!

Help @john_zakaria spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...