i want to execute a php script every day. i have a bash script containing below lines. and i was doing it with that script. but by this way, it can be executed from another computer. lets say webservername=”slmnbr” any body can call myscript with
xhttp://slmnbr/myscript.php.
i want to call it from just server.
BASE_URL=http://`get-webservername`
/usr/bin/wget --no-check-certificate --timeout=0 -O - "$BASE_URL/myscript.php"
thanks in advance
You need to have PHP CLI (command line interface) to do this. It often comes with the PHP installation package (or a separate package).
So as @James mentioned it you need to precede you script name with the CLI PHP executable which in windows is
php.exesomewhere in your install directory.In UN*X systems it’s somewhere in
/usr/binor/usr/local/binor/opt/local/bin. If it is in the PATH you can simply execute it like this:But keep in mind that running your script from server will be not the same as running from a webserver. For e.g. you won’t have the
POSTorGETvariables. So your script may not work.Update
You can make the cron ran scripts unreachable for your webserver by making it unreadable by the user who is running the PHP scripts by the http daemon (usually
www-data).I recommend to make it readable only by the user who is running it from cron:
Update2
If you’re running your script in cron with the same user as the webserver does, then at the top of your script stop it from being executed: