Wednesday, March 10, 2010

Determine if PHP file is being access via Cron

I ran into an issue where I needed to determine which config settings to load in my API. It picks up automatically whether I'm working locally or on the server. It kept loading the local configuration based on my code. So I asked some smarter people for some assistance and was given the right answer. This will determine whether it's being loaded via command line.

if (php_sapi_name() == 'cli') {
    return true;
} else {
    return false;
}

No comments:

Post a Comment