[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [kDev] PHP gurus: quick fix coding question...



Hello Daniel,

Monday, May 19, 2003, 10:53:01 AM, you wrote:

DH> WARNING: This email is intended for PHP coders only...

DH> This question is about how to run PHP code without having to call a web  
DH> page whilst passing it arguments like a perl cgi script.

Run it from the command line. If Linux, type:
php -d max_execution_time=20000 -f myfile.php myvar=first&anothervar=blah

If you get php 'not found' find the full path to it by:
locate php | grep bin
(eg for me it's /usr/local/bin/php)
Replace the 20000 with the number of seconds you want before it times
out.

Works also from Windows (I use cygwin to make Window CLI a doddle).

Put the following line at the top of your code (ie inside the PHP
file) to suck in your args from the command line:
        if ($argv[1]) parse_str($argv[1]);

This will turn myvar=first&anothervar=blah into $myvar and $anothervar

You can then stick this line in a file in /etc/cron.daily/. Eg:
cat > /etc/cron.daily/kendramail
#!/bin/bash
php -d max_execution_time=20000 -f myfile.php myvar=first&anothervar=blah
^D

Then it will run for your daily automatically.

DH> When I send out the newsletter I currently use zspamall.php. It allows  
DH> me to select a group of Kendra Participants and then cycles through  
DH> them sending a personalised email to each. But as the list of  
DH> participants grows so does the risk of a page timeout. It seems like  
DH> it's the sending-of-the-email that introduces a sizeable delay. I need  
DH> a quick and dirty fix. See:

DH> http://www.kendra.org.uk/develop- 
DH> code.php?page=%2Fzspamall.php&dowhat=Show+Source

DH> All I want to do is replace the line:

DH> mail($email,$subject,$message,"From: kendraNews <k@xxxxxxxxxxxxx>");

DH> with a call to a script.

DH> Oh, no, just thought... Will zspamall.php wait for a return from the  
DH> cgi script? In which case nothing will be gained and we'll need to put  
DH> the whole loop into the cgi script.

DH> Ideas anyone? Code anyone?

If the above doesn't work, or you have any probs understanding (rushed
reply, lots of work on), then email me.

Phillip.

-- 
Best regards,
 Phillip                            mailto:philliptemple@xxxxxxxxxxx