473,387 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PHP and Crontab and Current Directory

So I wrote a script and at the top it checks whether a file exists
like below

if (!file_exists("settings.ini"))
return false;

and the crontab entry:

00 08 * * 4 /usr/local/bin/php /home/user/scripts/test.php /dev/null
2>&1

however everytime it runs via cron, it can't find the file
settings.ini because it keeps looking for it in $HOME not in $HOME/
scripts/ where test.php resides

Why? And how can I re-code it to look in the current directory not in
$HOME? I tried ./settings.ini but without success

Apr 25 '07 #1
5 2970
Rik
Euhm, check my reply to your previous post?

--
Rik Wasmus

Estimated date being able to walk again: 01-05-2007.
Less then a week, hurray!
Apr 25 '07 #2
ro*********@googlemail.com wrote:
So I wrote a script and at the top it checks whether a file exists
like below

if (!file_exists("settings.ini"))
return false;

and the crontab entry:

00 08 * * 4 /usr/local/bin/php /home/user/scripts/test.php /dev/null
2>&1

however everytime it runs via cron, it can't find the file
settings.ini because it keeps looking for it in $HOME not in $HOME/
scripts/ where test.php resides

Why? And how can I re-code it to look in the current directory not in
$HOME? I tried ./settings.ini but without success
You can change the working directory with chdir() near the top of your script:

#!/usr/local/bin/php -q
<?php
chdir( '/home/user/scripts' );

//...
?>

That should make file_exists() work as expected.

If it doesn't do what you want it to do, you can try instead using:

ini_set( 'include_path', '/home/user/scripts' );

To temporarily set it as the (only) include path in the ini settings.

-Mike PII
Apr 25 '07 #3
Sorry Rik, didn't notice your reply to the last one (I didn't even notice the last one).

-Mike PII
Apr 25 '07 #4
Rik
Michael Placentra II wrote:
Sorry Rik, didn't notice your reply to the last one (I didn't even
notice the last one).

Hehehe, neither did he :-)

--
Rik Wasmus

Estimated date being able to walk again: 01-05-2007.
Less then a week, hurray!
Apr 25 '07 #5
On Apr 25, 10:26 pm, Rik <luiheidsgoe...@hotmail.comwrote:
Euhm, check my reply to your previous post?
Sorry about that, didn't show up and thought I had crossposted to too
many groups and got halted by anti-spam scripts.

Anyway your advice worked however the problem is I have to edit the
script everytime I run the program via Cron

Instead after some googling I found this method of instead:

00 11 * * * cd /home/user1/files/; /usr/local/bin/php test.php

Apr 26 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Arkascha | last post by:
Maybe someone can give me a short help with this... I got a server application in a LAMP environment doing batch tasks. A cronjob serves as a regular trigger, a metronom. The trigged...
4
by: David Bruno | last post by:
I set up a crontab using cpanel8 for the first time. It's just to run a very simple php script that sends an email and has one include() function. The first try at the crontab produced a...
3
by: Frank R. Suchy | last post by:
Hi, I want a php-script to maintain (some of) "my" cron jobs. Therefore it has to modify some crontab.txt (no problem) and has to execute crontab. But since php runs as the apache-user it...
3
by: rbt | last post by:
How can I safely append a crontab entry to a crontab file progammatically with Python? I need to handle crontabs that currently have entries and crontabs that are empty. Also, I'd like this to...
2
by: David Garamond | last post by:
I was thinking on how one would design an optimal (performance-wise) database of large number of schedules with crontab-like semantic. There will potentially be hundreds of thousands or even...
3
by: Sandman | last post by:
I have a PHP cli script, that backups my databases, using mysqldump via system(). When logged in with SSH, and launching the script with "./backup.php", all works just as it should, but when I...
4
by: Chr1s | last post by:
How do I execute a crontab command using php (not CLI) as user Joe? I don't have any problem getting output from commands such as 'ls' using passthru and exec but I am stumped with crontab. ...
2
by: martijn | last post by:
H! I have made a program that is checking if a program is running or not. If the program is not running then it must start the program again. in the /etc/crontab: * * * * ...
0
by: Martin Marcher | last post by:
Hello, is anyone aware of a crontab library. Possibly even more complete, something that will let me create/manipulate/delete crontab entries in a nice way and install the new crontab...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.