Petar Nedyalkov wrote:
actually, that path you gave depends on the system (OS), the way it's installed and a whole bunch of other stuff. I agree it is the default, and most common, location though.On Thursday 07 October 2004 13:17, Sheni R. Meledath wrote:
Hello:
We need to set up a cron to send an automated email at regular intervals. For this I need to execute a PHP file which retrieves the required information to be mailed. On my virtual server PHP is loaded as a module. Could you please let me know how can I execute a PHP file from the shell prompt.
I have tried with the following commands: % virtual /usr/local/etc/httpd/htdocs/onlineeml.php
It gives the below error: /usr/local/etc/httpd/htdocs/onlineeml.php: cannot open ?php: no such file
just insert:
#!/usr/bin/php -q
in the first line of the script and make it executable (chmod u+x .... ).
I am not able to execute any general php related commands (Eg: php -v, man p ect)from the Shell prompt. I am getting the error message as "php: Command not found.". I think this is because PHP is loaded as a module an not as a CGI version. In this context, could you please provide some details in executing a PHP script from the Shell prompt when the PHP is loaded as a module.
Regards
Sheni R Meledath Assistant Manager - Web Development ***************************************************************** Cyber Gear LLC P.O. Box 53735 Dubai, United Arab Emirates Tel: (971 4) 331-2627, Fax: (971 4) 331-8812 Email: sheni@xxxxxxxxxxxxxx, http://www.cyber-gear.com
VISIT OUR ASSOCIATE SITES: http://www.Click2Advertising.com http://www.DubaiCityGuide.com http://www.MiddleEastDirectory.com http://www.MiddleEastEvents.com http://www.MiddleEastPostBox.com http://www.PressReleaseNetwork.com *****************************************************************
This message has been checked for all known viruses by McAfee. No liability is accepted by virtue of checking this message and you are recommended to have in place your own anti-virus detection procedures.
A different way of executing such scripts is by adding a cronjob like * * * * * * /usr/bin/php -q /path/to/script
This does exactly the same as what Petar said, except that the script is passed to the interpreter, and thus the user that the crondaemon runs the script as only needs read (and doesn't need execute) permission to the script.
However; To find out the path to the interpreter, since you're saying you can't just call 'php -v' or any such commands, we'll need to investigate further.
One way of doing this is a bit "ugly", but it works. Instead of calling PHP directly, we'll call the server and request the php script (if you want, you can add tons of security shit in the call). We'll be doing this using wget (on Linux systems).
Imagine you'd like to run the following script: <?php // (let's presume it's located in www.example.net/scripts/bin/mail.php) if($_GET['user'] == 'a' && $_GET['pass'] == 'b') { mail('test@xxxxxxxxxxx', 'sub','body'); } else { header('Status: 404 Not Found'); exit; } ?>
You can call this as follows:
----
* * * * * * wget http://www.example.net/scripts/bin/mail.php?user=a&pass=b ; rm -f ./mail.php
----
The first part will call the server via an http connection to run the script and show its output. It then downloads it to the directory run from, and saves it. That is what wget does. The second part, after the semicolon, the 'rm -f ./mail.php' will make sure to get rid of the file after it's been run.
I hope this small example, will help you ;)
- Tul
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php