php-general Digest 10 Jun 2010 18:06:30 -0000 Issue 6791

Topics (messages 306004 through 306010):

Re: Question - foreach.
        306004 by: tedd
        306005 by: Paul M Foster
        306006 by: Shreyas
        306009 by: tedd

Re: PHP app & Server Load
        306007 by: Nathan Rixham

Re: Generic Email
        306008 by: Michiel Sikma

Redirect to
        306010 by: Ahmed Mohsen

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
At 7:19 AM +0530 6/10/10, Shreyas wrote:
PHP'ers,

I am reading a PHP book which explains foreach and at the end says : *'When
foreach starts walking through an array, it moves the pointer to
the beginning of the array. You don't need to reset an array before
walking through it with foreach.'*
*
*
*Does this mean - *
*1) Before I navigate the array, foreach will bring the pointer to the
starting key?*
*2) After the first index, it goes to 2nd, 3rd, and nth? *


Regards,
Shreyas

Shreyas:

This is one of those questions that you can test very easily, just initialize an array and try it.

<?php

$test = array(a, b, c, d);
foreach ($test as $value)
   {
   echo("value = $value <br>");
   }

?>

As the references show, there are two versions of the "foreach", the one above and this:

<?php

$test = array(a, b, c, d);
foreach ($test as $key => $value)
   {
   echo("$key= $key  value=$value <br>");
   }

?>

Note that you can pull-out the index (i.e., $key) as well as the value (i.e., $value) of each index. The "<br>" is only to add a linefeed in html.

This is a bit easier than using a for() loop.

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
On Thu, Jun 10, 2010 at 07:03:28AM -0400, tedd wrote:

> At 7:19 AM +0530 6/10/10, Shreyas wrote:
>> PHP'ers,
>>
>> I am reading a PHP book which explains foreach and at the end says : *'When
>> foreach starts walking through an array, it moves the pointer to
>> the beginning of the array. You don't need to reset an array before
>> walking through it with foreach.'*
>> *
>> *
>> *Does this mean - *
>> *1) Before I navigate the array, foreach will bring the pointer to the
>> starting key?*
>> *2) After the first index, it goes to 2nd, 3rd, and nth? *
>>
>>
>> Regards,
>> Shreyas
>
> Shreyas:
>
> This is one of those questions that you can test very easily, just
> initialize an array and try it.

+1

This is Tedd's modus operandi. His website(s) are full of exactly this
type of thing. And I have to agree. I can't count the number of
questions I *haven't* asked on this list, because I built a page to test
a particular concept. And this sort of activity (as opposed to just
reading about something) really locks in your understanding of a
concept.

Paul

-- 
Paul M. Foster

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

I tried and tested it but wanted a solid confirmation on it. I felt foreach
usage is better than manual way of next(), prev() et al.

Thanks for the comments. I consider the thread answered and solved unless
someone has anything more to add.

Regards,
Shreyas

On Thu, Jun 10, 2010 at 7:02 PM, Paul M Foster <pa...@quillandmouse.com>wrote:

> On Thu, Jun 10, 2010 at 07:03:28AM -0400, tedd wrote:
>
> > At 7:19 AM +0530 6/10/10, Shreyas wrote:
> >> PHP'ers,
> >>
> >> I am reading a PHP book which explains foreach and at the end says :
> *'When
> >> foreach starts walking through an array, it moves the pointer to
> >> the beginning of the array. You don't need to reset an array before
> >> walking through it with foreach.'*
> >> *
> >> *
> >> *Does this mean - *
> >> *1) Before I navigate the array, foreach will bring the pointer to the
> >> starting key?*
> >> *2) After the first index, it goes to 2nd, 3rd, and nth? *
> >>
> >>
> >> Regards,
> >> Shreyas
> >
> > Shreyas:
> >
> > This is one of those questions that you can test very easily, just
> > initialize an array and try it.
>
> +1
>
> This is Tedd's modus operandi. His website(s) are full of exactly this
> type of thing. And I have to agree. I can't count the number of
> questions I *haven't* asked on this list, because I built a page to test
> a particular concept. And this sort of activity (as opposed to just
> reading about something) really locks in your understanding of a
> concept.
>
> Paul
>
> --
> Paul M. Foster
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Regards,
Shreyas

--- End Message ---
--- Begin Message ---
At 9:32 AM -0400 6/10/10, Paul M Foster wrote:
On Thu, Jun 10, 2010 at 07:03:28AM -0400, tedd wrote:

 > This is one of those questions that you can test very easily, just
 initialize an array and try it.

+1

This is Tedd's modus operandi. His website(s) are full of exactly this
type of thing. And I have to agree. I can't count the number of
questions I *haven't* asked on this list, because I built a page to test
a particular concept. And this sort of activity (as opposed to just
reading about something) really locks in your understanding of a
concept.

Paul

Paul:

Now, if I could get the old memory to "lock in" and remember it, it would be great!

I spend much of my time thinking "Did I do that before?"

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
Dan Joseph wrote:
Hi,

This is slightly OT...

We're wrapping up a new PHP/MySQL driven web site built on the Zend
Framework.  We're anticipating a couple hundred thousand members with
several thousand of them coming to the site at once.  I'm trying to figure
out how to determine how many servers we need to support the load.

I've done initial testing on a Xeon 3220 server, but we're looking at an i7
cpu based server now.

Anyone know a good way to estimate load based on actually numbers compared
to benchmark results from intel on a faster server?

Hammer a single instance of the server with ab, get some figures on how many requests per second you can handle then divide by how much traffic you expect :)

Before investing in the servers, it may an idea to cache as much as you can and let apache serve static files where ever possible, even if the cache'd files are updated once every 10 seconds it's still a huge weight off the server in high traffic sites. Simple web server config tweaks can make a huge difference too, such as dropping the keep alive right down so requests are served and workers freed quicker, likewise with mysql query cache settings and zend optimizer for PHP (+similar).

Personally I tend to split setups for high traffic sites in to 3 tiers, static files on one server, dynamic + app code on another, and db on the final 3rd server - then scale up each tier adding servers as needed.

In all honesty, there is no way for anybody to tell you how many servers of what spec you'll need, because the biggest factor here your PHP code and MySQL queries, if you were purely serving static files though then circa 2000 requests per second is a good guestimate.

Best,

Nathan

--- End Message ---
--- Begin Message ---
On 9 June 2010 11:59, Richard Quadling <rquadl...@gmail.com> wrote:

> On 9 June 2010 09:08, Amit Bobade <a...@e-arth.in> wrote:
> > Hi friends,
> > I am new in  PHP. I want to know that how to send an email in HTML
> > format(i.e. with proper header, footer, etc) in PHP.
> >  Please suggest me with code.
> >
> > --
> > Thanks and Regards,
> > Amit
>
>

Well, you can simply use PHP's built in mail() function, documented here:
http://php.net/manual/en/function.mail.php
It's extremely easy to use, particularly if you copy and change the code
examples.

If you want something more powerful, try Swift Mailer:
http://swiftmailer.org/

Michiel

--- End Message ---
--- Begin Message ---
Hi folks,
I know that this is not a php question, but I'm sure it some kind related to it. I need to put my public files under "public" folder, and other includes files and database config in other folder not shown to the public, but i don't know how to do that. I hope if some one show me how to achieve this.

For example, this is the directory structure:

/root
--/includes
----db.php
----config.php

--/public
----/index.php
----/images
----/admin
------/login.php



I don't want to enter (example.com/public) to view index.php file. I just want to enter (example.com) and it redirects to the public folder and shows only (example.com/index.php) in the URL. And for login.php should display (example.com/admin/login.php) not (example.com/public/admin/login.php)

Kind regards,
Ahmed.

--- End Message ---

Reply via email to