Jump to content

Cron job


freeloader

Recommended Posts

Hi guys,

I have a linux installation (mandrake 8) using LAMP running a little home server. I created a second user account for telnet / SSH access besides the root. I logged into the server from myo other pc using Putty. Edited the crontab using crontab -e. Checked uo with crontab -l and it was installed. The file I ran the conjob for was crontest.php.

Content crontest.php:
[code]
<?php

writefile("logs/ITWORKS.txt","TEST");

function writefile($file,$text) {
$Handle = fopen($file, 'a');
$Data = "$text\n";
fwrite($Handle, $Data);
fclose($Handle);
}

?>
[/code]

This is what I got as return result in my mailbox:

[code]
Warning: fopen(logs/ITWORKS.txt): failed to open stream: No such file or directory in /opt/lampp/htdocs/crontest.php on line 7

Warning: fwrite(): supplied argument is not a valid stream resource in /opt/lampp/htdocs/crontest.php on line 9

Warning: fclose(): supplied argument is not a valid stream resource in /opt/lampp/htdocs/crontest.php on line 10 
[/code]

I checked and the chmod preferences for /logs are at 777.

Can anybody help me figure out what went wrong?

Thanks in advance.
Link to comment
https://forums.phpfreaks.com/topic/26889-cron-job/
Share on other sites

[quote author=freeloader link=topic=114595.msg466300#msg466300 date=1163208866]
I'll try that out, but the file works when I load it just in my browser... Only when using cron it gives error.
[/quote]

That's probably because relative to the URL of your current page, the file location is fine.  But I'm not sure what folder a cron job would run from--PROBABLY the root of your area (not the web root).

BTW when I said "full path" earlier, I didn't mean a full URL (http://www.mydomain/logs/ITWORKS.txt).  I meant a full server path (/home/username/public_html/logs/ITWORKDS.txt--this example is JUST an example.  What you need to put will depend on your specific server configuration).

Good luck!
Link to comment
https://forums.phpfreaks.com/topic/26889-cron-job/#findComment-122961
Share on other sites

Still doesn't work when using full path. Is that really the only thing that could've went wrong.

Maybe I should use full path on the HD like e:\linux\opt\ .. ?

This is what crontest.php looks like now:

[code]
<?php

writefile("/opt/lampp/htdocs/logs/ITWORKS.txt","TEST");

function writefile($file,$text) {
$Handle = fopen($file, 'a');
$Data = "$text\n";
fwrite($Handle, $Data);
fclose($Handle);
}

?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/26889-cron-job/#findComment-122965
Share on other sites

That's the only thing that I see.

Try putting the putting the following in a file by itself and load it in your browser.

[code]
<?php

phpinfo();

?>
[/code]

Look for a line that says [b]DOCUMENT_ROOT[/b].  Now does it say [b]/opt/lampp/htdocs/[/b]?  If yes, then that fixes THAT part and there must be some other problem too.
Link to comment
https://forums.phpfreaks.com/topic/26889-cron-job/#findComment-122977
Share on other sites

The only other possiblity that [b]I[/b] can see is that maybe the file doesn't exist (remember *nix filesystem is case sensitive--ITWORKS.txt isn't the same as itworks.txt.  Or there is a problem with your permission settings.

Try this above the call to your function:

if(file_exist("/opt/lampp/htdocs/logs/") && is_dir("/opt/lampp/htdocs/logs/")){
  dir("/opt/lampp/htdocs/logs/")
}else{
  echo "Folder missing";
  dir("/opt/lampp/htdocs/")
}
Link to comment
https://forums.phpfreaks.com/topic/26889-cron-job/#findComment-123908
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.