Languages :: PHP :: Can PHP call a cgi-script in the background? |
|||
| By: PHP newbee |
Date: 26/01/2003 00:00:00 |
Points: 50 | Status: Answered Quality : Excellent |
|
Hi I have a perl script that reads through a flat file and senda an e-mail to each address in the file, with a 2second sleep after each; so calling the cgi directly , causes a 2400 second "load" time (there are 1200 emails in the file). So I want to have the cgi execute in the background. The current cgi is called with a form's POST action, so I would like to have a php page as an "imtermediate" step. So the form will POSt all the variables to the PHP page, and then the php page must call the cgi script to execute in the background, but must also be able to POST the variables over to the cgi-script. Is this possible? Example? |
|||
| By: VGR | Date: 27/01/2003 07:02:00 | Type : Answer |
|
| yes, you should use some robot who will fire the HTTP request to your server at fixed intervals. I've one, free, it's called RobotOuaibe and you'll find it in the 3rd party tools in <A HREF="http://www.edainworks.com">http://www.edainworks.com</a> I use it all the time, to perform stats maintenance at midnight every day ;-) |
|||
| By: TheFalklands | Date: 28/01/2003 07:15:00 | Type : Comment |
|
| It is not possible to call a php script from the browser an than call in background a cgi-scvript. PHP and the called cgi is in this case an foreground process. |
|||
| By: RQuadling | Date: 28/01/2003 21:43:00 | Type : Assist |
|
| If you want to fake a call from a browser to your php script, then you can use curl. Script 1 - Sends emails based upon parameters (formmail.pl for example). Script 2 - Reads a file and calls script 1 with the parameters. <?php $fp = fopen("list.txt","r") or die("Cannot open email list."); while (!feof($fp)) { $sAddress = fgets($fp,1024); $ch = curl_init ("<A HREF="http://www.site.com/send_email.php?to=$sAddress">http://www.site.com/send_email.php?to=$sAddress</a>"); curl_exec ($ch); curl_close ($ch); } ?> This is VERY simplistic and may not work EXACTLY as you want, but, it will acheive what you want with some work. The above method is using the GET method. Curl will support the POST method no problem. More details from ... <A HREF="http://uk.php.net/manual/en/ref.curl.php">http://uk.php.net/manual/en/ref.curl.php</a> Alternatively, you can change your script to accept the info from GET instead. Richard. |
|||
| By: sumotimor | Date: 09/02/2003 18:52:00 | Type : Comment |
|
| You can try to do an exec('perl yourscript.pl'); More information is available in the php manual: <A HREF="http://www.php.net/manual/en/function.exec.php">http://www.php.net/manual/en/function.exec.php</a> |
|||
| By: RQuadling | Date: 02/06/2004 20:13:00 | Type : Comment |
|
| Hi. I've just read an article in PHP|Architect about contexts. This allows a similar level of functionality but without the need of an external library (like Curl) which may not be available on a shared server (like an ISP's hosting yours and a hundred others websites). As this magazine is via subscription only, I am not able to cut and paste any direct code and as I have not yet worked on this myself, I can only post links to further reading. The idea is that you create a context (which could be understood as the headers sent with a HTTP Request) and use it with fopen (and other functions). <A HREF="http://uk2.php.net/manual/en/function.stream-context-create.php">http://uk2.php.net/manual/en/function.stream-context-create.php</a> This simulates the use of curl. The article does mention that there are limits to this, but it may be a LOT easier than using curl for you. A forum for this article is at ... <A HREF="http://www.phparch.com/discuss/index.php/f/144/0">http://www.phparch.com/discuss/index.php/f/144/0</a> Regards, Richard. |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








