[PHP] Implode slows down file reading? [was: str_replace performance in large mailing script]
Hi all, I thought str_replace caused slow down of my mailing script, but it seems to be this line of code: $fd = implode(,file(http://www.domain.org/store/min/Mailing_template.html;) ); I first put the mailing template in $fd (only once) and then replace (str_replace) elements of it to individualize HTML emails. Btw im using php version 4.0.6. Are there better(faster) ways to read the contents of a file? Thanks! Fré -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] str_replace performance in large mailing script
Hi all, I have a mailing script that sends individualised mails to users(some users even get more than one mail). I have a template html mail file. I individualise this by using str_replace function. It is really slow. Can anyone point me to some performance tips? I was thinking of including an modified template(with variables) in my message part. Thanks for any help! Fred -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Cannot add header information - headers already sent
Hi ermelir, Thanks for your quick response! The http://www.aurelis.org/store/checkout_form.txt file shows in the browser with an empty first line: It may be an browser glitch. There's actually no space in the php file, i.e. it starts at line 1 with ?. I still receive the error. Any other thoughts? Thanks Fré -Original Message- From: ermelir [mailto:[EMAIL PROTECTED] Sent: dinsdag 12 augustus 2003 11:03 To: frederik feys Subject: Re: [PHP] Cannot add header information - headers already sent Hi, the problem is your empty first line: HTML header will be send if you call a function that send code to client browser (ex echo or print function) or if you have a empty line between php tags. for ex if you have - begin code ?php ... ? end code the empty first line is send to browser, so the HTML headers are send to; remove this line, you won't have errors any more - Original Message - From: frederik feys [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, August 12, 2003 10:59 AM Subject: [PHP] Cannot add header information - headers already sent Hi all, I'm stuck with this one: I have an checkout procedure: when people come to the overview page(step 2), they get: Warning: Cannot add header information - headers already sent by (output started at /usr/local/www/vhosts/aurelis.org/htdocs/header_aurelis.php:95) in /usr/local/www/vhosts/aurelis.org/htdocs/store/includes/functions/get_ca rtID.php on line 14 header_aurelis.php is where actual html output starts (template) i had a similar problem in my cart. I solved this by adding at the top of my script: $cookie = GetCartId(); This doesn't do the trick now :-( For your convenience i put the code here: http://www.aurelis.org/store/checkout_form.txt and a handler file: http://www.aurelis.org/store/checkout_form_handler.txt Can anyone shed some light on this? Thanks! Fré -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Cannot add header information - headers already sent
Hi all, Im stuck with this one: I have an checkout procedure: when people come to the overview page(step 2), they get: Warning: Cannot add header information - headers already sent by (output started at /usr/local/www/vhosts/aurelis.org/htdocs/header_aurelis.php:95) in /usr/local/www/vhosts/aurelis.org/htdocs/store/includes/functions/get_ca rtID.php on line 14 header_aurelis.php is where actual html output starts (template) i had a similar problem in my cart. I solved this by adding at the top of my script: $cookie = GetCartId(); This doesnt do the trick now :-( For your convenience i put the code here: http://www.aurelis.org/store/checkout_form.txt and a handler file: http://www.aurelis.org/store/checkout_form_handler.txt Can anyone shed some light on this? Thanks! Fré
RE: [PHP] Cannot add header information - headers already sent
Hi Marek, hi all, What do you mean by says it all? On that line the page title is outputted. I suspect something is wrong with the handler file: http://www.aurelis.org/store/checkout_form_handler.txt When i call http://www.aurelis.org/store/checkout_form.txt for step 1 (i.e. client personal register form) checkout_form gives no headers already sent. When the client proceeds to step 2 (i.e. an overview of purchase) the checkout_form_handler file is called. This does some calculations, etc.. and then redirects user to proper page using an header(location:) call. I suspect this step gives the header already sent. Any help appreciated! Fré -Original Message- From: Marek Kilimajer [mailto:[EMAIL PROTECTED] Sent: dinsdag 12 augustus 2003 12:15 To: frederik feys Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Cannot add header information - headers already sent output started at /usr/local/www/vhosts/aurelis.org/htdocs/header_aurelis.php:95 says it all. Look into the file at line 95. frederik feys wrote: Hi all, Im stuck with this one: I have an checkout procedure: when people come to the overview page(step 2), they get: Warning: Cannot add header information - headers already sent by (output started at /usr/local/www/vhosts/aurelis.org/htdocs/header_aurelis.php:95) in /usr/local/www/vhosts/aurelis.org/htdocs/store/includes/functions/get_ca rtID.php on line 14 header_aurelis.php is where actual html output starts (template) i had a similar problem in my cart. I solved this by adding at the top of my script: $cookie = GetCartId(); This doesnt do the trick now :-( For your convenience i put the code here: http://www.aurelis.org/store/checkout_form.txt and a handler file: http://www.aurelis.org/store/checkout_form_handler.txt Can anyone shed some light on this? Thanks! Fré -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] headers already sent and cookie problem
Hi Mike, hi all, I solved this nasty one! Happy. Your analysis is totally correct, Mike. Every visitor who puts an item in cart for the first time will get a cookie and... receives the error on his screen. And I, ... I didn't have this error message! What did it for me was: ? session_start(); include_once(../Connections/Aurelis.php); include_once($DOCUMENT_ROOT . /includes/functions/get_label.php); include_once($DOCUMENT_ROOT . /includes/functions/countries.php); include_once($DOCUMENT_ROOT . /store/includes/functions/calculate_shipping.php); include_once($DOCUMENT_ROOT . /store/includes/functions/get_cartID.php); $cookie = GetCartId(); -- so , i just called the function and assigned it to a variable and... gone with the wind! Thanks again Mike! Regards Fred -Original Message- From: Ford, Mike [LSS] [mailto:[EMAIL PROTECTED] Sent: vrijdag 18 juli 2003 18:20 To: 'frederik feys '; '[EMAIL PROTECTED] ' Subject: RE: [PHP] headers already sent and cookie problem -Original Message- From: frederik feys To: 'Ford, Mike [LSS]'; [EMAIL PROTECTED] Here's the URL: http://www.aurelis.org/store/cart.txt and the get_cartID: http://www.aurelis.org/store/includes/functions/get_cartID.txt -- I've only had time for a quick look, but I think I have an inkling of where your problem might be. It all seems to lie with the way you've implemented GetCartId() -- and the problem will only show up any time the cartId cookie is not already set. Basically, if the cookie is not set, GetCartId() generates a new ID and sets the cookie -- but this requires sending a header, and you can't do this once you've started output of the real page. So you must make you first call to GetCartId() *before* you send any output. Now, if we look at this fragment of code from /store/cart.txt: function ShowCart($lang) { global $connection,$lang_dir,$DOCUMENT_ROOT,$page_theme,$country_iso_code,$srch _ter m; /* ob_start(); //start buffering output */ $page_title=get_label(194,$lang,$connection); $page_tab=3; include_once($DOCUMENT_ROOT . /header_aurelis.php); $country_iso_code = $_GET[country_iso_code]; if($lang==EN){ $currency_symbol = $ ; } else{ $currency_symbol = euro; ; } $totalCost = 0; $show_cart = @mysql_query((select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = ' . GetCartId() . ' order by items.itemName asc),$connection); ... we can see that you include header_aurelis.php, which presumably outputs the initial part of your HTML, before you do $show_cart = @mysql_query ... ; which includes a call to GetCartId() -- which will attempt to set the cartId cookie if it's not already set, and will fail with the headers already sent error. So, overall, I'd say you've got to get/set your cartId earlier in the game -- and certainly before you call or include anything that outputs actual page content. This analysis also explains why the error is intermittent -- someone who has set the cartId cookie once will probably not see the error again until after the cookie expires 30 days later! Hope this helps (and you followed my somewhat rambling explanation!) Cheers! Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] headers already sent and cookie problem
Hi all, hi Mike, Here's the URL: http://www.aurelis.org/store/cart.txt and the get_cartID: http://www.aurelis.org/store/includes/functions/get_cartID.txt Thanks in advance! Fred -Original Message- From: Ford, Mike [LSS] [mailto:[EMAIL PROTECTED] Sent: woensdag 16 juli 2003 12:20 To: 'frederik feys'; [EMAIL PROTECTED] Subject: RE: [PHP] headers already sent and cookie problem -Original Message- From: frederik feys [mailto:[EMAIL PROTECTED] Sent: 16 July 2003 10:21 One nasty thing to debug is that the error only shows up from time to time. So now everything seems OK. What do i have now? I start my code with session_start Then include some files. The last one is get_cartID.php (remember?) Then i use several functions to have cart functionallity. In show_cart i include my page heading and then output further body and footer content. When I put the get_cartID include file AFTER include heading.php into my show cart function, the other functions start complaining they can't access the function get_cartID. Lots of text, sorry for that. But I still don't have the clue. Maybe you like to see my code? Yes, I think so -- I can't visualize enough of what's going on from your description to make further suggestions about what you might need to look at. From the sound of it, your files are quite big, so the best thing would be if you can put them up (as .phps or .txt) on your Web server and post their URLs to the list. If you can't do that, attach them to an email as .txt files. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] headers already sent and cookie problem
Thanks for your tips Mike! One nasty thing to debug is that the error only shows up from time to time. So now everything seems OK. What do i have now? I start my code with session_start Then include some files. The last one is get_cartID.php (remember?) Then i use several functions to have cart functionallity. In show_cart i include my page heading and then output further body and footer content. When I put the get_cartID include file AFTER include heading.php into my show cart function, the other functions start complaining they can't access the function get_cartID. Lots of text, sorry for that. But I still don't have the clue. Maybe you like to see my code? Any help welcome! Fred -Original Message- From: Ford, Mike [LSS] [mailto:[EMAIL PROTECTED] Sent: dinsdag 15 juli 2003 11:36 To: 'frederik feys'; [EMAIL PROTECTED] Subject: RE: [PHP] headers already sent and cookie problem -Original Message- From: frederik feys [mailto:[EMAIL PROTECTED] Sent: 15 July 2003 09:45 This is what i get: Warning: Cannot add header information - headers already sent by (output started at /home/u/r/html/store/cart.php:188) in /home/u/r/html/store/includes/functions/get_cartID.php on line 14 This says that on line 188 of store/cart.php you started outputting your HTML page, but you can't do that before the attempt to send headers on line 14 of store/includes/functions/get_cartID.php. Take a good look at line 188 of store/cart.php to see what you can do so that it is not starting HTML output, or move the header calls above the point where it is included/required. I know that the problem is the reading of the cookie and then after some sripting outputting page HTML. No, other way around. I started my code ob_start() and do an ob_flush() within a function(show_cart) (?might that be a problem?) Actually, that should be a preventer for the problem, so long as the ob_start() is executed before output is started -- perhaps your ob_start() should occur earlier in your script? Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] headers already sent-cookie-ob_flush()
Hi all, This is what i get: Warning: Cannot add header information - headers already sent by (output started at /home/u/r/html/store/cart.php:188) in /home/u/r/html/store/includes/functions/get_cartID.php on line 14 I know that the problem is the reading of the cookie and then after some sripting outputting page HTML. I started my code ob_start() and do an ob_flush() within a function(show_cart) (?might that be a problem?) Can anyone shed some light on this? Thanks! Fred -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] headers already sent and cookie problem
Hi all, This is what i get: Warning: Cannot add header information - headers already sent by (output started at /home/u/r/html/store/cart.php:188) in /home/u/r/html/store/includes/functions/get_cartID.php on line 14 I know that the problem is the reading of the cookie and then after some sripting outputting page HTML. I started my code ob_start() and do an ob_flush() within a function(show_cart) (?might that be a problem?) Can anyone shed some light on this? Thanks! Fred -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php