dgsmith Posted September 26, 2014 Posted September 26, 2014 I have a PHP file that is executed via batch file very frequently for live updating. This is a sort of "sync" file for reading/writing to a MySQL database. I am able to get it functioning absolutely fine when executed manually via a web browser (and my echo debug lines output the expected information), yet when I run the same PHP file via the command line, it seems to just not be capable of opening any file for reading, so the equivalent variables that are correct when executed on a web browser are blank when echoed through the command line. Is there a different way of handling reading of files when running a php script via the command line, or should it function exactly the same as when run via a browser? For instance: $k = "0"; $line = file("examplefile.log")[$k]; echo $line; The above will output the first line (line 0) of examplefile.log when run via a browser, yet in the command line it doesn't echo anything.. as if it's not able to read the file for some reason.
webman Posted September 26, 2014 Posted September 26, 2014 Which OS/environment is this running on? It's likely that it's an issue in finding the file relative to where the script is running or how it's being run. You could try entering the full path to the file in the parameter to file(), or something like: $line = file(dirname(__FILENAME__) . "/examplefile.log")[$k]; 1
dgsmith Posted September 30, 2014 Author Posted September 30, 2014 Which OS/environment is this running on? It's likely that it's an issue in finding the file relative to where the script is running or how it's being run. You could try entering the full path to the file in the parameter to file(), or something like: $line = file(dirname(__FILENAME__) . "/examplefile.log")[$k]; This was absolutely spot on.. it's something simple that I hadn't ever even considered.. I immediately assumed the most complex of reasons. Cheers
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now