php-general Digest 20 Jul 2007 19:13:03 -0000 Issue 4914

Topics (messages 259207 through 259226):

PHP Performance and System Load
        259207 by: Sascha Braun, CEO . ejackup.com
        259210 by: Sancar Saran
        259212 by: Colin Guthrie

Re: Cannot send session cache limiter...
        259208 by: Vanessa Vega
        259209 by: Paul Scott
        259216 by: David Robley

Re: Displaying HTML characters in real format
        259211 by: Nisse Engström

require and http
        259213 by: Suporte - DPRJ Sistemas
        259214 by: Zoltán Németh
        259215 by: Zoltán Németh

Symfony versus CakePHP?
        259217 by: Steve Finkelstein

Re: Pirate PHP books online?
        259218 by: Ryan A
        259225 by: Dotan Cohen

Re: Save email as .eml file
        259219 by: bkozora
        259226 by: bkozora

Re: PHP Brain Teasers
        259220 by: Daniel Brown

best technique to get the ID of the last inserted value
        259221 by: Marcelo Wolfgang
        259222 by: Richard Lynch
        259223 by: Brad Bonkoski
        259224 by: Uber Wannabe

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Dear People,

I developed a very large Application, which has at the moment strong
performace problems, while pages are loaded.

At the moment I am trying to lower the number of filesystem calls as
much as I can. I was able allready to lower the rate of filesystem
calls from round about 260 calls, which normaly included database calls
each time as well.

Now a page loads with round about 36 Filesystem and database calls, so
a improvement could really get established.

Now, as I might have imagined, the next problem is the object model of
the application which was very flexible in the past two years. But now
over time, for example the content management class grew up to 400 Kb
which is for a web application hell of a lot.

But it seems it is the only class at that enormous size.

I am using the PHP5 autoload functionality exclusive, so no other way
of loading classes is getting used.

No I started to come in mind of, splitting the cms class into smaller
potions. Will it really improve the page load, or will the object ini-
tialisations of the new appearing mass of classes have the same effect
as a class, stored in the eaccelator cache with a memory consumtion
round about 400 Kb?

Another question is, that I started to include my application framework
over a symlink placed in every webspace directory. I've read somewhere
that linux needs time to resolve a symlinks target.

Can this be a real performance issue? All datasets as well as images,
modules and all application relevant informations are loaded from that
symlinked place at the moment.

The webserver does only contain the webspace filesystem structure as
well as 5 line of PHP Code dummies, for every document in the content
management system, to avoid the usage of mod_rewrite.

It would be really wonderfull, to be able to discuss my questions with
you people here :))

Best Regards,


Sascha

--- End Message ---
--- Begin Message ---
Hi,

What is your desired performance level on what kind of hardware.

Have look memcached,

General performance tip do not include more than 10 files a page load.


I had CMS project too. Sometimes it uses 10 MB of php memory (generally uses 3 
mb of php memory). It uses Memcached in every way possible. Uses php Adodb 
for sql connection. Uses SQL based sessions. 

Except the external libs (adobs, php sniffer, phpmailer etc) no object method 
used. Also we had language, template support.

Generally be able to pump 5-7 pages per second on intel PII 350 mhz 320 mb ram 
IDE hdd. If I remove XSS detector (auto check for every member of  $_REQUEST 
array). It can reach 9 - 10 pages per second.

My Experiences
Looping around sql is bad.  Reading large flatfiles bad. 
Processing large texts are bad (Templating, Lots of preg replaces). 

If any of those operation was write once read many, store to memcached, then 
use it. 

Another simple performance tip.

Most of for examples of php look like this
for($x=0;$x<sizeof($arrSometing);$x++)

This is bad. In every cycle you call sizeof

this was good
$intSize = sizeof($arrSometing);
for($x=0;$x<$intSize;$x++)

if u use.
for($x=0;$x<$intSiz;++$x). You may gain another %10 

to determine costs of your functions use xdebug and kcachegrind.

Hope Helps.

Regards

Sancar

On Friday 20 July 2007 10:25:47 Sascha Braun, CEO @ ejackup.com wrote:
> Dear People,
>
> I developed a very large Application, which has at the moment strong
> performace problems, while pages are loaded.
>
> At the moment I am trying to lower the number of filesystem calls as
> much as I can. I was able allready to lower the rate of filesystem
> calls from round about 260 calls, which normaly included database calls
> each time as well.
>
> Now a page loads with round about 36 Filesystem and database calls, so
> a improvement could really get established.
>
> Now, as I might have imagined, the next problem is the object model of
> the application which was very flexible in the past two years. But now
> over time, for example the content management class grew up to 400 Kb
> which is for a web application hell of a lot.
>
> But it seems it is the only class at that enormous size.
>
> I am using the PHP5 autoload functionality exclusive, so no other way
> of loading classes is getting used.
>
> No I started to come in mind of, splitting the cms class into smaller
> potions. Will it really improve the page load, or will the object ini-
> tialisations of the new appearing mass of classes have the same effect
> as a class, stored in the eaccelator cache with a memory consumtion
> round about 400 Kb?
>
> Another question is, that I started to include my application framework
> over a symlink placed in every webspace directory. I've read somewhere
> that linux needs time to resolve a symlinks target.
>
> Can this be a real performance issue? All datasets as well as images,
> modules and all application relevant informations are loaded from that
> symlinked place at the moment.
>
> The webserver does only contain the webspace filesystem structure as
> well as 5 line of PHP Code dummies, for every document in the content
> management system, to avoid the usage of mod_rewrite.
>
> It would be really wonderfull, to be able to discuss my questions with
> you people here :))
>
> Best Regards,
>
>
> Sascha

--- End Message ---
--- Begin Message ---
Sancar Saran wrote:
> Another simple performance tip.
> 
> Most of for examples of php look like this
> for($x=0;$x<sizeof($arrSometing);$x++)
> 
> This is bad. In every cycle you call sizeof
> 
> this was good
> $intSize = sizeof($arrSometing);
> for($x=0;$x<$intSize;$x++)
> 
> if u use.
> for($x=0;$x<$intSiz;++$x). You may gain another %10 
> 
> to determine costs of your functions use xdebug and kcachegrind.

I've always used pre-increment in loops like you suggest as it was an
ingrained part of my C/C++ learning from a performance perspective. I
wasn't sure if the same was true in PHP but you seem to suggest it is,
so I feel justified now :)

Col

--- End Message ---
--- Begin Message ---
Hello to all!

I encountered this error when the site is uploaded on the server:

session_start(): Cannot send session cache limiter - headers already 
sent....

I already put session_start() on topmost part of the file..but i saved the 
file as utf-8..and that seems to be the problem..can anyone share their 
knowledge on this?

--- End Message ---
--- Begin Message ---
On Fri, 2007-07-20 at 16:01 +0800, Vanessa Vega wrote:
> I already put session_start() on topmost part of the file..but i saved the 
> file as utf-8..and that seems to be the problem..can anyone share their 
> knowledge on this?
> 
Set your error_reporting to at least E_ALL and check that there are no
problems there first. That should give you more of a clue as to what is
happening.

--Paul 

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/uwc2006/content/mail_disclaimer/index.htm 

--- End Message ---
--- Begin Message ---
Vanessa Vega wrote:

> Hello to all!
> 
> I encountered this error when the site is uploaded on the server:
> 
> session_start(): Cannot send session cache limiter - headers already
> sent....
> 
> I already put session_start() on topmost part of the file..but i saved the
> file as utf-8..and that seems to be the problem..can anyone share their
> knowledge on this?

I think that saving a file as UTF-8 places two characters at the very
beginning of the file; those characters will be passed to the server and
cause the error you are encountering.


Cheers
-- 
David Robley

"My hair's been cut off," Tom said distressfully.
Today is Sweetmorn, the 55th day of Confusion in the YOLD 3173. 

--- End Message ---
--- Begin Message ---
On Tue, 17 Jul 2007 17:59:01 -0500 (CDT), "Richard Lynch" wrote:

> On Tue, July 17, 2007 2:03 pm, Nisse Engström wrote:
>> On Fri, 13 Jul 2007 01:24:09 -0500 (CDT), "Richard Lynch" wrote:
>>>
>>> htmlspecialchars ONLY escapes four characters: < > & "
>>>
>>> htmlentities escapes ALL characters that need it
>>
>> What characters other than the four (or five)
>> NEED escaping, and why?
> 
> For example, some people occasionally find a need to write an o with
> an umlaut over it.

No way! :-)

> And sometimes they might type that right into a database form of some
> kind.
> 
> And if that's being output, it needs to be converted to an HTML entity
> so it will actually show up as an o with an umlaut, instead of, say,
> capital A with a tilda followed by a paragraph symbol.
> 
> Now, in some cases, if you are using UTF-8 (or UTF-16) and if the
> browser is supporting that, and if you've got the right headers and
> META tags, most modern browsers will do the right thing...

If you don't have the right headers and the right META tags,
you have bugs in your code. Are there any modern browsers
that don't support UTF-8 and the 8859-encodings?

> Or not, in the case of the reply window I'm typing into right now,
> which has turned your name into:
> 
> Nisse Engström
> 
> instead of:
> Nisse Engström
> 
> There are actually SIMPLER characters involving only ASCII, but I

[I assume you meant the so called "Extended ASCII". I can't
see any issues with (7-bit) ASCII.]

> thought this particular example would drive the idea home better :-)

Not really. An o with an umlaut (which, by the way, is not
an umlaut at all in my language but a letter in its own
right) does not NEED escaping in the same way that the
special chars do.

> This script might help as well:
> 
> <pre><?php
>   for ($o = 0; $o < 256; $o++){
>     echo "$o: '", htmlspecialchars($o), "' versus '",
> htmlentities($o), "'\n";
>   }
> ?></pre>

[Replace "($o)" with "(chr($o))"]

Both columns are the same unless I start mucking about
with the browsers character encoding. What exactly is
this supposed to prove? That you failed to provide a)
the page's character encoding, and b) a charset argument
to htmlentities()?


/Nisse

--- End Message ---
--- Begin Message ---
Hello!

I am returning to PHP and having some problems.

Can anyone tell me if 
require_once("http://www.mydomain.com.br/includes/teste.php";) really do not 
work?

If I especify the complete path for my local server 
(/srv/www/htdocs/mysite/php/teste.php) it works fine (I did it when using 
version 4). 

The manual says it works but it is not working for me.

Thank you

Deleo

PHP  5.2.0
MySQL 5.0.26
Apache 2.2.3
Suse Linux 10.2

--- End Message ---
--- Begin Message ---
2007. 07. 20, péntek keltezéssel 09.17-kor Suporte - DPRJ Sistemas ezt
írta:
> Hello!
> 
> I am returning to PHP and having some problems.
> 
> Can anyone tell me if 
> require_once("http://www.mydomain.com.br/includes/teste.php";) really do not 
> work?
> 
> If I especify the complete path for my local server 
> (/srv/www/htdocs/mysite/php/teste.php) it works fine (I did it when using 
> version 4). 
> 
> The manual says it works but it is not working for me.

check the allow_url_fopen setting in php.ini
http://hu2.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen

hope that helps
Zoltán Németh

> 
> Thank you
> 
> Deleo
> 
> PHP  5.2.0
> MySQL 5.0.26
> Apache 2.2.3
> Suse Linux 10.2

--- End Message ---
--- Begin Message ---
2007. 07. 20, péntek keltezéssel 09.30-kor Suporte - DPRJ Sistemas ezt
írta:
> Checked and ON!
> 


sorry I forgot that you need allow_url_include to be on too.
check that too.

btw, what do you mean by "not working"? does it throw any error? or
what?

greets
Zoltán Németh


(ps. sorry I forgot to include the list in my reply - but you forgot
that too ;) )

> Deleo
> 
> ----- Original Message ----- 
> From: "Zoltán Németh" <[EMAIL PROTECTED]>
> To: "Suporte - DPRJ Sistemas" <[EMAIL PROTECTED]>
> Cc: "PHP - General List" <[EMAIL PROTECTED]>
> Sent: Friday, July 20, 2007 9:25 AM
> Subject: Re: [PHP] require and http
> 
> 
> > 2007. 07. 20, péntek keltezéssel 09.17-kor Suporte - DPRJ Sistemas ezt
> > írta:
> >> Hello!
> >>
> >> I am returning to PHP and having some problems.
> >>
> >> Can anyone tell me if 
> >> require_once("http://www.mydomain.com.br/includes/teste.php";) really do 
> >> not work?
> >>
> >> If I especify the complete path for my local server 
> >> (/srv/www/htdocs/mysite/php/teste.php) it works fine (I did it when using 
> >> version 4).
> >>
> >> The manual says it works but it is not working for me.
> >
> > check the allow_url_fopen setting in php.ini
> > http://hu2.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen
> >
> > hope that helps
> > Zoltán Németh
> >
> >>
> >> Thank you
> >>
> >> Deleo
> >>
> >> PHP  5.2.0
> >> MySQL 5.0.26
> >> Apache 2.2.3
> >> Suse Linux 10.2
> >
> > -- 
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> > 
> 

--- End Message ---
--- Begin Message ---
All,

I'm terribly sorry if this is a redundant inquiry. I'm a rather inexperienced developer who's catching on quickly, and looking for a framework to build out a project I've been assigned. I'm more of a read a book and try things out type of learner.

My question to those with more experience, what exactly is the difference between CakePHP and Symfony? I'm looking into both of them for a potential framework to make robust and scalable code. They both seem to try to obtain the same goals with their project, however Symfony has text written about it, etc.

Anyway, thank you for any insight.

- sf

--- End Message ---
--- Begin Message ---
Hey,

Sorry your work was stolen but dont hold your breath waiting for that site to 
close down. I have no idea who your publishers are but I _realllly_ doubt they 
have more clout than M$, the MPAA, RIAA, SONY, Pixar etc coz they went after 
thepiratebay and looked like fools:

http://thepiratebay.org/legal

I *DONT* wish to sound mean but the fact is, your work is going to continue to 
be stolen and other than complain, theres little you can do about it...so try 
to ignore it and dont let something like this stop you from writing again as i 
am sure there are many people out there that would rather get their copy via 
legal means, enough to support you anyway.

HTH.

Cheers!
R


David Powers <[EMAIL PROTECTED]> wrote: Crayon Shin Chan wrote:
> What makes you think any of the authors are subscribed to this list?

I am subscribed to this list, and I'm disgusted that somebody posted the 
URL to the pirate site. I see that more than 2,000 copies of my "PHP 
Solutions: Dynamic Web Design Made Easy" have been downloaded.

Although eBooks are cheaper than the printed version, the royalties to 
an author are much higher (no printing, storage, or delivery costs). I'm 
not starving, but the loss in revenue is far from trivial, and reduces 
the incentive to continue to write.

I have reported the site to my publisher. Even if it's closed down, my 
work has already been stolen.

David Powers

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)
       
---------------------------------
Get the free Yahoo! toolbar and rest assured with the added security of spyware 
protection. 

--- End Message ---
--- Begin Message ---
On 19/07/07, Zoltán Németh <[EMAIL PROTECTED]> wrote:

I didn't want to get involved in this thread, though it was interesting
to read...
However, an idea just came into my mind: what if you, as the author,
could offer a download for a price which would be the same as what you
get after a sold paper copy? According to what you just said, it would
be much cheaper for the download than for a paper copy, which might
cause more or less of the downloaders of the pirated file to download it
legally and pay this smaller price to you.
I admit that it won't stop pirating, but it might be good for those who
are willing to pay to you, but either can't afford the paper copy or are
not willing to pay to the publishing company - and it might increase
your revenues a bit too.

greets
Zoltán Németh


An additional benefit is that there are those who _prefer_ the
electronic version to the dead trees. At least, I do.

Dotan Cohen

http://lyricslist.com/
http://what-is-what.com/

--- End Message ---
--- Begin Message ---
Thanks for your help. How would I go about getting procmail to forward it? 

What I currently have is a script that connects to a free email address that
collects bounces captured from newsletters the system has sent. I'm using
IMAP to connect to the mailbox, then looping through and trying to create
the eml files. I don't know if the procmail approach would work, as I can
only access my email through IMAP (not even POP3).

Last night while examining some eml files and cross referencing to the value
imap_body returned, I was thinking I may be able to just dump that to a
file. Do you think that would work? There's a class on phpclasses that
handles bounces, but it requires eml files
(http://www.phpclasses.org/browse/package/2691.html).

Here is my code as it is now, don't know if that would help or not:

############### CODE ############### 

$imap = imap_open("{mail.messagingengine.com:143}INBOX", "**", "**");

$message_count = imap_num_msg($imap);

echo "<h3>$message_count Emails Returned</h3>";


for ($i = 1; $i <= $message_count; ++$i) 
{
        $header = imap_header($imap, $i);
        
        if (isset($header->from[0]->personal)) 
        {
                $personal = $header->from[0]->personal;
        } 
        else 
        {
                $personal = $header->from[0]->mailbox;
        }

        $eml = "date : $header->Date \n";
        $eml .= "from : $personal 
<{$header->from[0]->[EMAIL PROTECTED]>from[0]->host}> \n";
        $eml .= "subject : $header->Subject \n";
        $eml .= "to : $personal 
<{$header->to[0]->[EMAIL PROTECTED]>from[0]->host}> \n";
        
        $eml .= imap_body($imap, $i, "FT_PEEK")."\n";
        
        $messageID = imap_bodystruct($imap, $i, "message_id");

        echo "<h3>header</h3><pre style=\"color:red;\">";
        print_r($header);
        echo "</pre>";

        echo "<h3>Body</h3><pre style=\"color:red;\">";
        print_r(imap_body($imap, $i, "FT_PEEK"));
        echo "</pre>";

        $file = "../eml/".rand(1111, 9999).".eml";   
        if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; }  
        if (!fwrite($file_handle, $eml)) { echo "Cannot write to file"; }  
        echo "<h4>You have successfully written data to $file</h4>";   
        fclose($file_handle);   
        
}


imap_close($imap);



Thanks,
Bobby


Handa Utsav wrote:
> 
> Hi there,
> 
> Well it can be easily done. Just input your mail (make 'procmail' fwd
> it) to your script & script would save it as .eml .
> 
> Try to use the following code for script :
> 
> ######## CODE #####################
> 
> <?php 
> 
> $email = "";
> ## Read
> E-mail                                                                        
>                          
> $fd = fopen("php://stdin", "r");
> while (!feof($fd)) {
> $email .= fread($fd, 1024);
> }
> fclose($fd);
> 
> # Save email
> $handle = fopen("$path/$file_name.eml","a+");
>  if (!$handle) {
>    fwrite($log_handle," Failed ");
>  }
>  else {
>    fwrite($handle,"$email");
>    fclose($handle);
>  }
> 
> 
> ?>
> 
> Hope this helps you out.
> 
> 
> Greetings
> Utsav Handa
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Save-email-as-.eml-file-tf4103444.html#a11712721
Sent from the PHP - General mailing list archive at Nabble.com.

--- End Message ---
--- Begin Message ---
I think I found a solution. Must admit I feel pretty down for spending so
much time on this when the solution was so simple, but I couldn't find too
much info on PHP's imap functions. Hopefully this will be indexed and help
developers in the future.

PHP has a function that saves the message in a valid RFC1892 multipart
report format:

$res = imap_savebody($imap, "../eml/test.eml", 2);

Thank you all for your help!
-- 
View this message in context: 
http://www.nabble.com/Save-email-as-.eml-file-tf4103444.html#a11714301
Sent from the PHP - General mailing list archive at Nabble.com.

--- End Message ---
--- Begin Message ---
   This isn't necessarily a brain-teaser, but it's still pretty cool.
Dice (the employment site) has a new advertisement out there that
says the following:

====
What's missing from your job?

<?php
format = 'The %2s contains %1d orders';
printf(format, num, location
?>
====

   I thought it was a pretty simple for of genius, so to speak.

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

--- End Message ---
--- Begin Message ---
Hi all,

I'm a newbie in PHP, and I want to know what's the best technique you guys use when you need to get the id of the last inserted value in the database.

My first thought is to do a SELECT on the db and get the last id, but I know that if I have two almost simultaneous connections I may get the wrong one, so that's the why of my question.

TIA
Marcelo Wolfgang

--- End Message ---
--- Begin Message ---
On Fri, July 20, 2007 1:10 pm, Marcelo Wolfgang wrote:
> I'm a newbie in PHP, and I want to know what's the best technique you
> guys use when you need to get the id of the last inserted value in the
> database.
>
> My first thought is to do a SELECT on the db and get the last id, but
> I
> know that if I have two almost simultaneous connections I may get the
> wrong one, so that's the why of my question.

Every DB has a function to handle this.

Use the one appropriate to your DB.

In MySQL, it's:
http://php.net/mysql_insert_id

You're on your own to rtfm and find the others, but never ever try to
roll your own!

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--- End Message ---
--- Begin Message ---
One easy solution would be to get the ID before you do the insert....
i.e. in Oracle you would run the query:
select some_id_generating_seq.nextval from dual

and then you would use that id to insert and you would know the id after that...and the DB would take care of locking and such. So, check the help pages for your DB of choice to see what support they have for something like that.

-B

Marcelo Wolfgang wrote:
Hi all,

I'm a newbie in PHP, and I want to know what's the best technique you guys use when you need to get the id of the last inserted value in the database.

My first thought is to do a SELECT on the db and get the last id, but I know that if I have two almost simultaneous connections I may get the wrong one, so that's the why of my question.

TIA
Marcelo Wolfgang


--- End Message ---
--- Begin Message ---
However, wouldn't obtaining the id in that manner still possibly lead to
duplication?  The DB would take care of the locking on the inserts, but the
inserts would be populated from a non-locking select, right?  Which means
that, with two similar transactions getting ready to occur, you could end up
with two Inserts with the same id.

Just my thought... I'd stick with the DB's built-in functionality for that.
As usual, all the information on that is freely available online.


-- N/A

-----Original Message-----
From: Brad Bonkoski [mailto:[EMAIL PROTECTED] 
Sent: Friday, July 20, 2007 1:50 PM
To: Marcelo Wolfgang
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] best technique to get the ID of the last inserted value

One easy solution would be to get the ID before you do the insert....
i.e. in Oracle you would run the query:
select some_id_generating_seq.nextval from dual

and then you would use that id to insert and you would know the id after 
that...and the DB would take care of locking and such.
So, check the help pages for your DB of choice to see what support they 
have for something like that.

-B

Marcelo Wolfgang wrote:
> Hi all,
>
> I'm a newbie in PHP, and I want to know what's the best technique you 
> guys use when you need to get the id of the last inserted value in the 
> database.
>
> My first thought is to do a SELECT on the db and get the last id, but 
> I know that if I have two almost simultaneous connections I may get 
> the wrong one, so that's the why of my question.
>
> TIA
> Marcelo Wolfgang
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---

Reply via email to