php-general Digest 8 Jan 2005 10:05:46 -0000 Issue 3215

Topics (messages 205851 through 205861):

Re: Multiple POP accounts on Webmail Front
        205851 by: Jamie Alessio

Re: On large application organization [long and possibly boring]
        205852 by: Richard Lynch
        205854 by: Joe Harman

Re: migrating to PHP 5 + Apache 2 from PHP 4.3.8 + Apache 1.3.33.
        205853 by: Richard Lynch

Need a Calender class that can access a DB
        205855 by: Phillip S. Baker

Pagination Optimization
        205856 by: Bruno B B Magalh�es
        205857 by: M. Sokolewicz

Re: E-mails with mail() as UTF-8
        205858 by: Manuel Lemos

preg match
        205859 by: Chandana Bandara
        205860 by: Rory Browne

Which script runs first?
        205861 by: gustav.varupiraten.se

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 ---
IIRC, It does not do IMAP, it does not handle secure connections, it does
not ...


Squirrelmail does support IMAP. I'm using it to access a courier IMAP server with no problems.

From http://www.squirrelmail.org/about.php
"It includes built-in pure PHP support for the IMAP and SMTP protocols"

I found the Horde system to be a huge pain to set up and install. Maybe that has changed since I tried it a few years ago but I was quickly up and running with squirrelmail in just a few minutes so that's my recommendation if it does in fact support multiple pop accounts. Alternatively, you could always use something like fetchmail (http://catb.org/~esr/fetchmail/) to pull the multiple pop accounts down into a single account and then check that one account via webmail. Might give you faster access instead of having your webmail app doing pop accesses to a bunch of different accounts?

- Jamie
--- End Message ---
--- Begin Message ---
Jay Blanchard wrote:
> [snip]
> Richard Lynch speaks:
> But it ends up being not all that maintainable, and you end up having to
> open up and track too many files with too many interactions when you go
> down this route.
>
> I abandoned this style and have never regretted it.
>
> YMMV
> [/snip]
>
> In favor of what?

Depends on the site -- on its size/scale mostly.

Small/Medium sites:
The URL matches a file, and that file includes any common code, and
handles the specific actions of that URL.  Tracking errors and code logic
is simplified immensely.

For a larger site, I don't believe in a cookie-cutter approach, so don't
have a single "answer" for you.  All I know is, I haven't had a
monster-switch to deal with an "action" since then, and when I have to go
maintain code that *DOES* have a monster-switch, I know why.  It's a PITA
to figure out what's pulling what in where, and I end up with too many
windows open with code scatter across too many files.

I guess the only "rules" I can give are:
1. Given a bug report about URL X, and only X, I should know exactly which
file to open to find the most likely source of the bug -- the distinctive
parts that make X be different from all the other pages.

2. Given a bug report that seems to involve multiple URLs, I should know
just from the error report, where the problem is most likely to be.

Throwing everything in a monster-switch right away doubles the number of
potential files, at minimum, but even higher than that for weird syntax
errors or simple mistakes in the switch login, which never ends up being
as simple as a switch().  You end up having almost ALL the files being
included being suspect when things get weird.  Get rid of that switch, and
have a more reasonable rational systematic way to know what's included,
and more importantly, what code is *NOT* *POSSIBLY* included, and your
possible source of Bug #8766533 shrinks dramatically.

Got my fire-proof undies on now.

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
This is Definatley a good conversation... I've realy thought of doing
it this way... but i do agree with the person who said that 'having to
keep track of a ton of different files could get complicated" ... i
can't imagine the performance difference would be that big... but then
again, i suppose it is relative to how big your applicatin is going to
be

Cheers!
Joe


---------- Forwarded message ----------
From: Jay Blanchard <[EMAIL PROTECTED]>
Date: Thu, 6 Jan 2005 14:30:23 -0600
Subject: [PHP] On large application organization [long and possibly boring]
To: PHP Mailing Lists <[email protected]>


Good afternoon gurus and gurettes,

If I have a large app what is the difference, other than having a very
large file, of doing this

switch($action){
       /* several dozen cases to follow */
       case "foo":
               writing out all of the code
       break;
}

and this

switch($action){
       /* several dozen cases to follow */
       case "foo":
               include that will handle processing this case
       break;
}

Correct me if I am wrong, but includes (and/or requires) will get all of
the code in all of the cases regardless if the case is being processed.
That being the case the code would essentially be the same length. Given
that, would there be an efficieny issue?

This would (the second way) also make the project easier to work on by
multiple programmers at the same time, similar to modular work being
done by programmers on C++ projects.

One of the reasons for doing this is so that global includes and certain
class definitions, such as an error checking function relavent to most
cases, can be included once.

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

--- End Message ---
--- Begin Message ---
symbulos partners wrote:
> Jason Barnett wrote:
>> exercise for myself, but then again I don't need to either.  ;)  This
>> would also be something that would be a great benefit to share with the
>> PHP community if you decide to compile this list of thread-safe
>> extensions.
>
> If we could share a bit of the effort with someone else, we would be
> available (February). Eventually we could host the page on our website, f
> necessary.
>
> We could have a simple php base page where people could flag libraries /
> sets of functions after checking. A simple table, in order to understand.
>
> We could manage it by e-mail eventually.

After checking?

There is *NO* exhaustive test to do, from everything I've ever heard...

Now if you want to come up with a test harness that claims to stress-test
some given code-base, with version numbers of all the under-lying code,
and hardware, come to think of it, and try to track the amount of testing
that has been done, and assign probability curves to the thread-safeness
of any given combination...

It ain't gonna be no simple table, though, really.

You might get somebody to say "Core PHP is Thread-safe"

They might even believe that.

They *might* even be right.

For their version of PHP.

On their OS.

Under that *version* of their OS.

With their hardware.

It don't mean a whole lot to anybody who doesn't have that *exact* same
setup.

You'd almost have to work out a list of all known variables, and then a
weighting system for (number-of-hours-run X
number-of-concurrent-processes) multiplied by the server load to give each
report a "score"

If I tell you it's "been fine" on my low-traffic servers, it don't mean
squat.  If Rasmus tells you "PHP X + MySQL Y + OS Z == Good" on Yahoo,
that has some meaning, but not a whole lot if you change *any* of the
variables in the equation.

So then, you'd have a very large (and quite sparse, probably) matrix of
the probability that any given combination of every software package (and
hardware?) is thread-safe.

Not saying it's not a Good Idea, nor that you shouldn't be doing this:  I
just want you to understand that you've severely under-estimated the scale
and scope of the problem to be addressed, and have a concomitant
simplisitic design going here.

Make it complex enough to be useful, and make it easy to search and report
on various combinations, it could be a real boon.

But if your site just says "PHP 4.1.3 + MySQL 3.23.4 == Good"...  I'm not
going to put much faith in that for thread-safety.

But maybe I'm just a negative guy :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

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

I have the need to find a calender class/script. What I am trying to do is
have a view by month calender that lists all classes for the month. People
can see the names of the classes in the month display and then click on the
link and get the detailed information about the class through this view.

We have a custom look for the class descriptions and such so I do not need
the whole standard calendar stuff that is often out there. Just the main
calendar feature that will allow me to pull records from a MySQL DB and let
me create links to the appropiate pages that I am coding.

The database with the classes is already in place. So I am just looking for
a view events by month class or script that I can use and plug into the DB I
already without having to build this thig from scratch.

Is there anyone that already has something that I can use or can you point
me to something on sourceforge or phpbuilder or some other site I am not
aware of.

I would appreciate any points in the right direction.
Thanks in advance.
--
Blessed Be

Phillip

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

currently I have a function in my framework�s mysql driver , that fetch paginated results... Here it�s:

===============================================================
        /*****************************************************
        *  Fetch paginated results
        *****************************************************/
        function fetch_paginated($query='',$page=1,$itens=20)
        {
                $this->query($query.' LIMIT 
'.(($page*$itens)-$itens).','.$itens);
                
                if($this->num_rows() > 0)
                {
                        while($this->fetch_array())
                        {
                                $results[] = $this->row;
                        }
                }
                else
                {
                        return null;
                }
                
                $this->query($query.' LIMIT 0,'.(($page*$itens)-$itens));
                $this->pages_before = ceil($this->num_rows()/$itens);
                
                $this->query($query.' LIMIT 
'.($page*$itens).',1000000000000000000');
                $this->pages_after = ceil($this->num_rows()/$itens);
                
                $this->query($query);
                $this->total_pages = ceil($this->num_rows()/$itens);
                                
                return $results;
        }
===============================================================

My question is: Is there ANY way to speed up this function, or any way to fetch paginated results quicker? I had a project list, without pagination, and when I added the pagination function, it slowed down up to 0.0125 secs. Before it was running at 0.0600 more or less, and now it�s running at 0.07 to 0.075...

Best Regards,
Bruno B B Magalh�es

--- End Message ---
--- Begin Message --- first of all, you're running 4 queries here. 4 queries is a lot! Especially when you don't need more than 2 ;)
the problem here is that your queries are pretty "unknown" to this function. Although it does a nice result for that unknowing, there's a few minor things that make it faster.


First of all, would be using less queries.
What I usually do is issue a query like this:
"SELECT count(some_unique_col) WHERE (that_where_clause_youre_using_in_the_select_query)"
then, we do some math.


$pages_before = $page-1;
$rows_before = $pages_before*$itens;

$rows_after = $total_number_of_rows-($page*$itens);
$pages_after = ceil($rows_after/20);

Then do the actual selecting of the rows using the limit.


The thing that makes it slow in your example is the fact that 4 times you're selecting ALL data from the relevant rows, and buffer it. You buffer it, but don't use any of it, except for the number of rows. Mysql does a far quicker job at this than PHP would, so use mysql. :)
Then, you're using 3 queries to determine the rows around the page; even though, with a bit of simple math, you can calculate it. And trust me on this, simple math is faster ;)


anyway, hope that helped.

Bruno B B Magalh�es wrote:
> Hi guys,
>
> currently I have a function in my framework�s mysql driver , that fetch
> paginated results... Here it�s:
>
> ===============================================================
> /*****************************************************
> * Fetch paginated results
> *****************************************************/
> function fetch_paginated($query='',$page=1,$itens=20)
> {
> $this->query($query.' LIMIT '.(($page*$itens)-$itens).','.$itens);
>
> if($this->num_rows() > 0)
> {
> while($this->fetch_array())
> {
> $results[] = $this->row;
> }
> }
> else
> {
> return null;
> }
>
> $this->query($query.' LIMIT 0,'.(($page*$itens)-$itens));
> $this->pages_before = ceil($this->num_rows()/$itens);
>
> $this->query($query.' LIMIT
> '.($page*$itens).',1000000000000000000');
> $this->pages_after = ceil($this->num_rows()/$itens);
>
> $this->query($query);
> $this->total_pages = ceil($this->num_rows()/$itens);
>
> return $results;
> }
> ===============================================================
>
> My question is: Is there ANY way to speed up this function, or any way
> to fetch paginated results quicker? I had a project list, without
> pagination, and when I added the pagination function, it slowed down up
> to 0.0125 secs. Before it was running at 0.0600 more or less, and now
> it�s running at 0.07 to 0.075...
>
> Best Regards,
> Bruno B B Magalh�es

--- End Message ---
--- Begin Message ---
Hello,

on 01/07/2005 01:33 AM Kimmo Alm said the following:
Hey again!

I'm having major trouble using mail() to deliver UTF-8 e-mails.

They get sent and delivered successfully, but seem to be... messed up when they arrive (they go through my ISP's relay e-mail server).

My headers basically look like this: "From: Test <[EMAIL PROTECTED]>\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\n".

I want to be able to use UTF-8 chars both in the subject and the body.

When I check the letters in my e-mail client (Opera's built-in one -- M2), it shows "UTF-16". Also, the headers look different than from the ones I send.

Is the relay server altering my letters? What the hell is happening?

When you use UTF-8 encoding it may end up including 8 bit characters. In this case you need to use quoted-printbale encoding to compose the message body and some MTA may filter the unencoded 8 bit bytes . For the headers it is the same except the encoding is q-encoding.


If you do not know how to encode messages with quoted-printable and q-encoding, you may want to try this popular MIME message composing and sending class. Just specify that the default encoding charset is utf-8 and it will be sent without corruption:

http://www.phpclasses.org/mimemessage


--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html

--- End Message ---
--- Begin Message ---
This php script perform matching text of some certain URLs. but in this 
preg_match it wont match few patterns <  _ .
with help of this script , can some body help me to match the other all 
patterns .............plz ?



<?php

$user="root";
$pass="****";
$db="aa";
        $dblink = mysql_connect("localhost:3306", "$user", "$pass")or 
die("Could not connect to db");
        mysql_select_db($db) or die ("can't select the db");
        
        $result = mysql_query ("select indexNo,Reply from Acknowledgement order 
by indexNo") or die ("Invalid query");
        while ( $rset= mysql_fetch_array($result)) {
                /* Lets check the reply with the database*/
                $chk_msg= $rset["Reply"];
                //echo "checking $chk_msg in $msg<br>";
                if ( preg_match("/$chk_msg/", "$msg", $match) ) {
                        // match found
                        $SQL="update Status set Status = 'UP' where 
ServiceNo=".$rset["ServiceNo"];
                        mysql_query ("$SQL") or die ("Invalid 2nd query");
                }else{
                        // SERIVCE DOWN
                        // nothing to do here.
                        //echo "No match..<br>";
                }

        }
        mysql_close($dblink);

?>

thanx in advance, 
chandana

--- End Message ---
--- Begin Message ---
I'm not sure what you're trying to do with preg_match, since the
parameters you send to it, are from the database, and an  undeclared
variable $msg(which is what exactly). Unless you give us examples of
the arguments to preg_match, and what you expect the results should
be, as well as what they are, we can't really be of much help.

Having that said:
You are using "/$chk_msg/" as the first  parameter. since you are
simply putting /'s around $chk_msg, this leads me to suggest that you
don't need regex at all, and perhaps would be better using some of the
string functions. strpos() ( http://www.php.net/strpos ) springs to
mind.

Just a few tips:
As an aside, I notice that you are connecting to localhost:3306. Just
incase you didn't know, when you connect to localhost through
mysql_connect, assuming you are on a unix host, it uses a unix socket,
regardless if  you specify a port. If you want to override this
behavour, and use TCP sockets, you can connect to 127.0.0.1.


On Sat, 8 Jan 2005 00:37:34 +0600, Chandana Bandara
<[EMAIL PROTECTED]> wrote:
> This php script perform matching text of some certain URLs. but in this 
> preg_match it wont match few patterns <  _ .
> with help of this script , can some body help me to match the other all 
> patterns .............plz ?
> 
> <?php
> 
> $user="root";
> $pass="****";
> $db="aa";
>         $dblink = mysql_connect("localhost:3306", "$user", "$pass")or 
> die("Could not connect to db");
>         mysql_select_db($db) or die ("can't select the db");
> 
>         $result = mysql_query ("select indexNo,Reply from Acknowledgement 
> order by indexNo") or die ("Invalid query");
>         while ( $rset= mysql_fetch_array($result)) {
>                 /* Lets check the reply with the database*/
>                 $chk_msg= $rset["Reply"];
>                 //echo "checking $chk_msg in $msg<br>";
>                 if ( preg_match("/$chk_msg/", "$msg", $match) ) {
>                         // match found
>                         $SQL="update Status set Status = 'UP' where 
> ServiceNo=".$rset["ServiceNo"];
>                         mysql_query ("$SQL") or die ("Invalid 2nd query");
>                 }else{
>                         // SERIVCE DOWN
>                         // nothing to do here.
>                         //echo "No match..<br>";
>                 }
> 
>         }
>         mysql_close($dblink);
> 
> ?>
> 
> thanx in advance,
> chandana
>

--- End Message ---
--- Begin Message ---
Hi there!

I have two frames, one with left.php in the left frame and one with
main.php in the right frame.

I refresh the contents of main.hp at the end of left.php.  (With help of
Javascript actually, maybe could be done with HEADER(...))

My Question:
Is it ALWAYS so that left.php must be executed before the right frame is
loaded? I wonder this because a session-variable are set in left.php that
main.php is dependent of. So this session-variable must be set before
main.php is loaded.


/G
@varupiraten.se

--- End Message ---

Reply via email to