php-general Digest 1 Jan 2008 04:42:21 -0000 Issue 5210
Topics (messages 266425 through 266448):
Re: why is <option '97' selected>Japan</option> not highlighted
266425 by: Tom Chubb
266430 by: Richard Lynch
Re: simplexml problem
266426 by: Nathan Nobbe
266427 by: Dani Castaños
266428 by: Nathan Nobbe
Re: script stoped working over christmas ?
266429 by: Joker7
Re: Simple RegEx question
266431 by: Richard Lynch
Re: Php exec
266432 by: Richard Lynch
Re: Try{} Catch()
266433 by: Richard Lynch
Re: PHP interprocesss communication
266434 by: Richard Lynch
Re: Sending SMS via PHP
266435 by: Richard Lynch
Re: imap_mail()
266436 by: Richard Lynch
Re: html to doc and pdf ??
266437 by: Richard Lynch
Re: PHP5 Speed Issues
266438 by: Richard Lynch
266441 by: Michael McGlothlin
266442 by: Nathan Nobbe
266443 by: Michael McGlothlin
266444 by: Nathan Nobbe
Re: I hate bugs...Mysqli issue
266439 by: Richard Lynch
Re: Which file called the function?
266440 by: Richard Lynch
266445 by: Nathan Nobbe
About search engine usability
266446 by: Jim Webber
266447 by: Darren Whitlen
266448 by: David Wonderly
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 ---
On 31/12/2007, Mary Anderson <[EMAIL PROTECTED]> wrote:
> in my <select> scrolling list?
>
> Here is the offending code (abbreviated)
> <select name="sr_location_id" class="" size=10 >
> <option value='94' >Italy</option>
> <option value='97' selected>Japan</option>
> <option value='252' >Jersey</option>
> <option value='294' >Jiangsu</option>
> <option value='295' >Jiangxi</option>
>
> I have data series which have a location specified. I wish to edit the
> data series. I select the location from the database (Note: database
> stuff is not a problem) and display a scrolling list with the location
> specified by that data series highlighted. Problem is, even though the
> option is marked selected, the Japan entry in the scrolling list does
> not highlight.
>
> The offending page may be viewed at
>
> http://www.demog.berkeley.edu/~maryfran/memdev/edit_series.php?sr_data_series_id=2
>
>
> Sometimes when it loads, Japan is highlighted correctly. Sometimes
> nothing is highlighted. Sometimes some random option in the list is
> highlighted. Similar behavior is observed in the data series types
> scrolling list next to the locations list on the page.
>
> I have been using Firefox 2.0.0.3. I just tried it out on IE7 and it
> seems to work OK. Maybe it is a browser problem, but the XDynamic HTML
> Definitive Reference seems to say that the selected attribute on option
> works OK with mozilla.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
This is not PHP related, but I'll point you in the right direction.
I have looked at your code and it is different to the source on the
page found online.
The line;
<option value='97' selected="selected">Japan</option> (Online version)
Is different to:
<option value='97' selected>Japan</option>
--- End Message ---
--- Begin Message ---
FireFox may be "remembering" whatever you last selected.
That's a browser "feature" you have to live with.
Move along, nothing to see here :-)
On Sun, December 30, 2007 9:46 pm, Mary Anderson wrote:
> in my <select> scrolling list?
>
> Here is the offending code (abbreviated)
> <select name="sr_location_id" class="" size=10 >
> <option value='94' >Italy</option>
> <option value='97' selected>Japan</option>
> <option value='252' >Jersey</option>
> <option value='294' >Jiangsu</option>
> <option value='295' >Jiangxi</option>
>
> I have data series which have a location specified. I wish to edit
> the
> data series. I select the location from the database (Note: database
> stuff is not a problem) and display a scrolling list with the location
> specified by that data series highlighted. Problem is, even though
> the
> option is marked selected, the Japan entry in the scrolling list does
> not highlight.
>
> The offending page may be viewed at
>
> http://www.demog.berkeley.edu/~maryfran/memdev/edit_series.php?sr_data_series_id=2
>
>
> Sometimes when it loads, Japan is highlighted correctly. Sometimes
> nothing is highlighted. Sometimes some random option in the list is
> highlighted. Similar behavior is observed in the data series types
> scrolling list next to the locations list on the page.
>
> I have been using Firefox 2.0.0.3. I just tried it out on IE7 and it
> seems to work OK. Maybe it is a browser problem, but the XDynamic
> HTML
> Definitive Reference seems to say that the selected attribute on
> option
> works OK with mozilla.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
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/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
On Dec 31, 2007 7:11 AM, Dani Castaños <[EMAIL PROTECTED]> wrote:
> Hi all!
>
> I'm using simplexml to load an xml into an object.
> The XML is this:
> <?xml version="1.0"?>
> <request>
> <customerID>3</customerID>
> <appName>agenda</appName>
> <ticketType>cticket_agenda_server</ticketType>
> <ticketTypeID>1</ticketTypeID>
> <platformID>1</platformID>
> <ticketAction>addUsersToGroup</ticketAction>
> </request>
>
> When I do this:
>
> $file = simplexml_load_file( 'file.xml' );
> $ticketType = $file->ticketType;
>
> What i really have into $ticketType is a SimpleXMLElement... not the
> value "cticket_agenda_server"... What am I doing wrong?
cast the value to a string when you pull it out if you want to use it that
way:
<?php
$xml =
<<<XML
<?xml version="1.0"?>
<request>
<customerID>3</customerID>
<appName>agenda</appName>
<ticketType>cticket_agenda_server</ticketType>
<ticketTypeID>1</ticketTypeID>
<platformID>1</platformID>
<ticketAction>addUsersToGroup</ticketAction>
</request>
XML;
$file = new SimpleXMLElement($xml);
$ticketTypeAsSimpleXmlElement = $file->ticketType;
$ticketTypeAsString = (string)$file->ticketType;
$ticketTypeAnalyzer = new ReflectionObject($ticketTypeAsSimpleXmlElement);
echo (string)$ticketTypeAnalyzer . PHP_EOL;
var_dump($ticketTypeAsString);
?>
-nathan
--- End Message ---
--- Begin Message ---
Nathan Nobbe escribió:
On Dec 31, 2007 7:11 AM, Dani Castaños <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
Hi all!
I'm using simplexml to load an xml into an object.
The XML is this:
<?xml version="1.0"?>
<request>
<customerID>3</customerID>
<appName>agenda</appName>
<ticketType>cticket_agenda_server</ticketType>
<ticketTypeID>1</ticketTypeID>
<platformID>1</platformID>
<ticketAction>addUsersToGroup</ticketAction>
</request>
When I do this:
$file = simplexml_load_file( 'file.xml' );
$ticketType = $file->ticketType;
What i really have into $ticketType is a SimpleXMLElement... not the
value "cticket_agenda_server"... What am I doing wrong?
cast the value to a string when you pull it out if you want to use it
that way:
<?php
$xml =
<<<XML
<?xml version="1.0"?>
<request>
<customerID>3</customerID>
<appName>agenda</appName>
<ticketType>cticket_agenda_server</ticketType>
<ticketTypeID>1</ticketTypeID>
<platformID>1</platformID>
<ticketAction>addUsersToGroup</ticketAction>
</request>
XML;
$file = new SimpleXMLElement($xml);
$ticketTypeAsSimpleXmlElement = $file->ticketType;
$ticketTypeAsString = (string)$file->ticketType;
$ticketTypeAnalyzer = new
ReflectionObject($ticketTypeAsSimpleXmlElement);
echo (string)$ticketTypeAnalyzer . PHP_EOL;
var_dump($ticketTypeAsString);
?>
-nathan
Thanks! Problem fixed... But I think PHP must do the cast automatically.
I think it's a bug fixed in a further version than mine as I've read
--- End Message ---
--- Begin Message ---
On Dec 31, 2007 10:09 AM, Dani Castaños <[EMAIL PROTECTED]> wrote:
> Thanks! Problem fixed... But I think PHP must do the cast automatically.
> I think it's a bug fixed in a further version than mine as I've read
>
no problem; but just fyi, its not a bug; the behavior is as expected per the
manual:
http://us3.php.net/manual/en/ref.simplexml.php
*Example#6 Comparing Elements and Attributes with Text*
To compare an element or attribute with a string or pass it into a function
that requires a string,
you must cast it to a string using *(string)*. Otherwise, PHP treats the
element as an object.
if you use an operation that casts implicitly, such as echo, you dont have
to cast yourself;
otherwise you do :)
-nathan
--- End Message ---
--- Begin Message ---
In news: [EMAIL PROTECTED] - Jochem Maas wrote :
>> Joker7 schreef:
>>
>> ...
>>
>>>>>>
>>>>>> config.php
>>>>>> <?php
>>>>>> $max_summary = 6;
>>>>>> $max_latest = 7;
>>>>>> $summary_template = "t_summary.tp";
>>>>>> $article_template = "t_article.tp";
>>>>>> $password = "password";
>>>>>> latest.php
>>>>>> <?php
>>>>>>
>>>>>> require('config.php');
>>>>>>
>>>>>> $filename = "article_summary.php";
>>>>>>
>>>>>> #- open article summaries
>>>>>> if(file_exists($filename)){
>>
>> full path to this file is not being used.
>>
>>>>>> $fh = fopen($filename, "r");
>>>>>> $old_news = fread($fh, filesize($filename));
>>>>>> fclose($fh);
>>>>>> }
>>
>> does the file exist? is it readable by php? is there anything in the
>> file? have you looked at the output source to see what if anything
>> was actually outputted?
>>
>>>>>>
>>>>>> #- get article
>>>>>> $articles = explode("<!--ARTICLE-->", $old_news);
>>>>>> $i=0;
>>>>>> foreach ( $articles as $article ){
>>>>>> if(count($articles)>$i){
>>>>>> if($max_latest >= $i++){
>>>>>> print $article;
>>>>>> }
>>>>>> }
>>>>>> }
>>>
>>> No error message it's as if it working ,but not ,if I change the
>>> path or any thing else I get the apporiate error message.
>>>
>>> Chris
Yes works with full path --- has been working for an age with out ,but then
thats life......
Cheers
Chris
--- End Message ---
--- Begin Message ---
Find Weitz's "The Regex Coach" (Linux and Windows) and install it and
play around.
You'll learn more in one day from the pretty color syntax highlighting
than reading the perl books/pages for months.
On Mon, December 24, 2007 9:34 pm, M5 wrote:
> I'm learning regular expressions, and trying to figure out what's
> possible and what's not. Any ideas of how to create a preg_match
> expression to parse following three lines:
>
> Calgary, AB T2A6C1
> Toronto, ON T4M 0B0
> Saint John, NB E2L 4L1
>
> ...such that it splits each line into City, Province and Postalcode
> (irrespective of occasional white space), e.g.:
>
> Array
> (
> [city] => "Calgary",
> [prov] => "AB",
> [postal] => "T2A 6C1"
> )
>
> Array
> (
> [city] => "Toronto",
> [prov] => "ON",
> [postal]=> "T4M 0B0"
> )
>
> Array
> (
> [city] => "Saint John",
> [prov] => "NB",
> [postal]=> "E2L 4L1"
> )
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
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/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
http://php.net/imap_createmailbox
On Sun, December 23, 2007 4:31 pm, mattias wrote:
> If i use courier-mta
> Can i create a php script wich create mailboxes?
> And users
> Hope any understand
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
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/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
On Sun, December 23, 2007 3:50 pm, Martin Alterisio wrote:
> It's not supposed to be practical, it's just a way to handle errors.
> You
> shouldn't rely on try/catch for algorithm implementation.
>
> You create exceptions for errors and unexpected behavior. Then in some
> other
> part of the system you use try/catch to prevent the code from
> terminating
> abruptly. You catch the exception (you should know which exceptions
> can be
> thrown), and act accordingly. Either closing resources, add a log
> message
> with debug information, and/or sending an error message to the user.
Except that once you start trying to integrate several large bodies of
code, you have NO IDEA what exceptions can be thrown, and even less
idea where they didn't get caught and handled properly.
Worse, many times the library[ies] you are integrating to an abysmal
job of doing anyting intelligent with the catch block, and you're
stuck with something even worse than set_error_handler.
try/catch works great for small/medium projects, or even large
well-documented projects perhaps, but as soon as you start trying to
integrate several projects...
Well, in MY experience, try/catch just ended up biting me in the butt...
ymmv
naiaa
ianal
--
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/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
On Sun, December 23, 2007 2:48 pm, Christophe Gosiau wrote:
> The problems I have with this setup are:
> 1) How does my PHP application finds out what thread is handling the
> TCP
> connection according to the user who is logged in into the
> application?
I do not think you can do this...
> 2) What is the best way to send a command to this thread? Shared
> Memory?
> Socket Pairs? Named Pipes?
Write your own inter-process language that sends out some kind of HTTP
response that tells your .net client to do whatever it is you want it
to do.
Or, possibly, have the PHP script open up a socket
http://php.net/sockets to the .net application, and send commands and
data identifying itself sufficiently to make your .net application do
what it's supposed to.
> 3) Has anyone already made a similar setup or does anyone has good
> documentation about interprocess communication?
Shared Memory is not for the faint of heart, but you'll still need
some kind of back-n-forth to identify who's doing what, I think, so
you might as well send the data with that...
Though I guess you could have a sort of "global" shared memory and
keep a running list of "to do" on there for the .net and PHP apps to
manage...
--
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/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
The 160 byte limit is carrier/handset dependent, and goes as low as
140 for some Canadian carriers.
The cell phone companies are happy to provision you with a gateway
account, if you can prove you are not a cell-spammer and will pay them
money.
If not, you are at the mercy of free systems designed for casual
limited use by end users, and abusing that with a PHP script that
could send lots of messages would be a very Bad Idea -- They'll just
block you as soon as you get going.
The core gear is owned by the phone companies. They're not interested
in providing free spammer access wide open to the general public for
some reason...
On Sun, December 23, 2007 8:59 am, Bastien Koert wrote:
>
> Sending proper SMS messges requires that you use an SMS gateway or buy
> a cellular modem. SMS is essentially XML will the message body limited
> to 160 characters.
>
> do some googling to get more information
>
> bastien
> ----------------------------------------
>> Date: Sun, 23 Dec 2007 08:30:29 +0330
>> From: [EMAIL PROTECTED]
>> To: [EMAIL PROTECTED]
>> Subject: [PHP] Sending SMS via PHP
>>
>> Hi,
>>
>> How can i send SMS messages via PHP? How can i set SMS-headers
>> (UDH)?
>> Does anyone know some article/class/package about this issue?
>>
>> Thank you in advance,
>> -b
>
> _________________________________________________________________
> Discover new ways to stay in touch with Windows Live! Visit the City @
> Live today!
> http://getyourliveid.ca/?icid=LIVEIDENCA006
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
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/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
$headers = "From: \"Thomas Le\" <[EMAIL PROTECTED]>\nMailed-by:
whatever\n";
mail('[EMAIL PROTECTED]', 'test', 'test', $headers);
NOTE:
The RFC says use \r\n between headers.
gmail is broken and will puke if you do.
Complaint to gmail, please.
On Sat, December 22, 2007 10:27 pm, Thomas Le wrote:
> How do I structure the $additionalHeaders string so that it is useful?
> Is
> there a specific order the headers have to be in? How do I delimit
> multiple
> headers? I want the from and mailed-by fields to be modified by this
> variable when mailed from the PHP script. I am getting the server name
> of my
> host instead of the domain name of my site. Minor thing because most
> people
> probably dont look at headers, but I want it to be professional
> looking in
> case someone does.
>
> Thank you,
>
> Thomas Le
> "Choose a job you love, and you'll never have to work a day in your
> life." -
> Confucius
>
--
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/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
http://php.net/pdf
I'm betting there is a PEAR module to write Word docs.
Or you could use COM objects, if you are running PHP on a Windows box
that has Word installed.
On Sat, December 22, 2007 9:55 pm, Me2resh Lists wrote:
> Dear All,
>
> after suffering with asp.net, i finally convinced the company to turn
> the
> application we are using to PHP
> but my concern is,
> what is the easiest and best way to convert html that is generated
> from
> mysql databse to microsoft word and pdf files ????
>
> the application will run on a linux server
>
> can anyone help please ????
>
> any help would be appreciated
>
> thanks in advance,.
>
> Regards,
> Me2resh
>
--
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/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
On Sat, December 22, 2007 12:25 pm, Sascha Braun wrote:
> Hi Fellows,
>
> I figured out, that PHP5 runs faster when I am not inherit classes,
> I hope I use the right word.
>
> I mean the class sub_class extends main_class notation.
>
> As well I figured out, that I in most cases should references in
> foreach loops. like
>
> foreach($array as $key => &$value) {
>
> }
>
> Lots of memory is saved by that.
>
> Now I would like to know, what other speed improvements might be
> possible. What about autoload of classes, will it improve speed
> when I throw the code out?
>
> Are there other things I should take care of.
>
> I would like to know as much as possible. Please go deep into your-
> self and tell me every little thing on how you improved your applica-
> tions for speed and memory optimisation, to make this thread the best
> compendium on performance and memory optimisation.
>
> Thank you very much, fellows and a merry merry christmas!
I never optimize code unless there's a problem with its performance...
Why one would tweak code endlessly to maximize performance when that's
not needed is beyond me...
But maybe I'm just a Luddite.
--
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/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
Richard Lynch wrote:
On Sat, December 22, 2007 12:25 pm, Sascha Braun wrote:
Hi Fellows,
I figured out, that PHP5 runs faster when I am not inherit classes,
I hope I use the right word.
I mean the class sub_class extends main_class notation.
As well I figured out, that I in most cases should references in
foreach loops. like
foreach($array as $key => &$value) {
}
Lots of memory is saved by that.
Now I would like to know, what other speed improvements might be
possible. What about autoload of classes, will it improve speed
when I throw the code out?
Are there other things I should take care of.
I would like to know as much as possible. Please go deep into your-
self and tell me every little thing on how you improved your applica-
tions for speed and memory optimisation, to make this thread the best
compendium on performance and memory optimisation.
Thank you very much, fellows and a merry merry christmas!
I never optimize code unless there's a problem with its performance...
Why one would tweak code endlessly to maximize performance when that's
not needed is beyond me...
But maybe I'm just a Luddite.
Hardware is cheaper than man hours. Just throw more CPU power at the
problem.
--
Michael McGlothlin
Southwest Plumbing Supply
--- End Message ---
--- Begin Message ---
On Dec 31, 2007 3:37 PM, Michael McGlothlin <[EMAIL PROTECTED]> wrote:
> Richard Lynch wrote:
> > On Sat, December 22, 2007 12:25 pm, Sascha Braun wrote:
> >
> >> Hi Fellows,
> >>
> >> I figured out, that PHP5 runs faster when I am not inherit classes,
> >> I hope I use the right word.
> >>
> >> I mean the class sub_class extends main_class notation.
> >>
> >> As well I figured out, that I in most cases should references in
> >> foreach loops. like
> >>
> >> foreach($array as $key => &$value) {
> >>
> >> }
> >>
> >> Lots of memory is saved by that.
> >>
> >> Now I would like to know, what other speed improvements might be
> >> possible. What about autoload of classes, will it improve speed
> >> when I throw the code out?
> >>
> >> Are there other things I should take care of.
> >>
> >> I would like to know as much as possible. Please go deep into your-
> >> self and tell me every little thing on how you improved your applica-
> >> tions for speed and memory optimisation, to make this thread the best
> >> compendium on performance and memory optimisation.
> >>
> >> Thank you very much, fellows and a merry merry christmas!
> >>
> >
> > I never optimize code unless there's a problem with its performance...
> >
> > Why one would tweak code endlessly to maximize performance when that's
> > not needed is beyond me...
> >
> > But maybe I'm just a Luddite.
> >
> >
> Hardware is cheaper than man hours. Just throw more CPU power at the
> problem.
>
thats only true until poorly designed software cant be spread across
machines
due to a monolithic nature.
get an opcode cache and index the database; that will probly absolve any
noticeable
speed problems.
-nathan
--- End Message ---
--- Begin Message ---
Nathan Nobbe wrote:
On Dec 31, 2007 3:37 PM, Michael McGlothlin <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
Richard Lynch wrote:
> On Sat, December 22, 2007 12:25 pm, Sascha Braun wrote:
>
>> Hi Fellows,
>>
>> I figured out, that PHP5 runs faster when I am not inherit
classes,
>> I hope I use the right word.
>>
>> I mean the class sub_class extends main_class notation.
>>
>> As well I figured out, that I in most cases should references in
>> foreach loops. like
>>
>> foreach($array as $key => &$value) {
>>
>> }
>>
>> Lots of memory is saved by that.
>>
>> Now I would like to know, what other speed improvements might be
>> possible. What about autoload of classes, will it improve speed
>> when I throw the code out?
>>
>> Are there other things I should take care of.
>>
>> I would like to know as much as possible. Please go deep into
your-
>> self and tell me every little thing on how you improved your
applica-
>> tions for speed and memory optimisation, to make this thread
the best
>> compendium on performance and memory optimisation.
>>
>> Thank you very much, fellows and a merry merry christmas!
>>
>
> I never optimize code unless there's a problem with its
performance...
>
> Why one would tweak code endlessly to maximize performance when
that's
> not needed is beyond me...
>
> But maybe I'm just a Luddite.
>
>
Hardware is cheaper than man hours. Just throw more CPU power at the
problem.
thats only true until poorly designed software cant be spread across
machines
due to a monolithic nature.
get an opcode cache and index the database; that will probly absolve
any noticeable
speed problems.
-nathan
Well obviously you can always write horrible code but if you write code
that is easy to maintain it's usually not that kind of code.
--
Michael McGlothlin
Southwest Plumbing Supply
--- End Message ---
--- Begin Message ---
On Dec 31, 2007 3:47 PM, Michael McGlothlin <[EMAIL PROTECTED]> wrote:
> Nathan Nobbe wrote:
> > On Dec 31, 2007 3:37 PM, Michael McGlothlin <[EMAIL PROTECTED]
> > <mailto:[EMAIL PROTECTED]>> wrote:
> >
> > Richard Lynch wrote:
> > > On Sat, December 22, 2007 12:25 pm, Sascha Braun wrote:
> > >
> > >> Hi Fellows,
> > >>
> > >> I figured out, that PHP5 runs faster when I am not inherit
> > classes,
> > >> I hope I use the right word.
> > >>
> > >> I mean the class sub_class extends main_class notation.
> > >>
> > >> As well I figured out, that I in most cases should references in
> > >> foreach loops. like
> > >>
> > >> foreach($array as $key => &$value) {
> > >>
> > >> }
> > >>
> > >> Lots of memory is saved by that.
> > >>
> > >> Now I would like to know, what other speed improvements might be
> > >> possible. What about autoload of classes, will it improve speed
> > >> when I throw the code out?
> > >>
> > >> Are there other things I should take care of.
> > >>
> > >> I would like to know as much as possible. Please go deep into
> > your-
> > >> self and tell me every little thing on how you improved your
> > applica-
> > >> tions for speed and memory optimisation, to make this thread
> > the best
> > >> compendium on performance and memory optimisation.
> > >>
> > >> Thank you very much, fellows and a merry merry christmas!
> > >>
> > >
> > > I never optimize code unless there's a problem with its
> > performance...
> > >
> > > Why one would tweak code endlessly to maximize performance when
> > that's
> > > not needed is beyond me...
> > >
> > > But maybe I'm just a Luddite.
> > >
> > >
> > Hardware is cheaper than man hours. Just throw more CPU power at the
> > problem.
> >
> >
> > thats only true until poorly designed software cant be spread across
> > machines
> > due to a monolithic nature.
> > get an opcode cache and index the database; that will probly absolve
> > any noticeable
> > speed problems.
> >
> > -nathan
> Well obviously you can always write horrible code but if you write code
> that is easy to maintain it's usually not that kind of code.
thats pretty subjective; ive worked w/ plenty of 'easy to maintain' code
that could
only have hardware thrown at it by a load balancer. which i consider a real
mess.
even then the design of the load balancer will have to maintain request
forwarding
to particular hosts unless the code already supports or is given support for
session
storage in a common location all the webservers can address.
i personally am not a fan of the 'just throw hardware at it' adage, if it
can be called that.
i was recently at the d.c. php conference and heard a talk from a gentleman
on behalf
of yahoo. he says they are *very* picky about getting new hardware; yahoo
wants clear
rationale for the addition of any new hardware into the system. in short;
they advocate
writing solid code because it saves them money in the long run.
what i see happening when people throw hardware at their problem is that in
early stages
it works great. then further down the road the software is unable to be
easily spread to
multiple systems and then guess what; you end up spending man hours to do
something that
could have been done in the first place. another issue is randomly added
machines can be
hard to maintain because their roles are not clearly defined.
what im saying is adding hardware to a system is natural and relevant, but
ensure it is a
good decision by evaluating alternatives before arbitrarily 'throwing
hardware at the problem'.
-nathan
--- End Message ---
--- Begin Message ---
On Fri, December 21, 2007 10:50 am, Jason Pruim wrote:
> <?php
>
>
>
> $link = mysqli_connect($server, $username, $password, $database) ;
>
> /* check connection */
> if (mysqli_connect_errno()) {
> printf("Connect failed: %s\n", mysqli_connect_error());
> exit();
> }
>
>
>
> ?>
> It looks valid to me... as long as it's connecting... the username/
> password/database are all correct, I can log in from the command line
> with no issue....
Perhaps it is valid, when the database is up and running.
But if your DB was re-started for some reason, the link won't be there
while it's restarting will it?
You've GOT to write code to handle the $link being false instead of
marching blindly off the cliff.
You are not a lemming. :-)
--
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/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
On Thu, December 20, 2007 1:54 pm, George Pitcher wrote:
> I have a functions file with over 400 functions (and that may be too
> many -
> but it works). I've been adding some error reporting in to my PEAR::DB
> queries, but wanted to know which page triggered the function. I went
> theough my php pages and gane each one a $pg variable at the start
> containing the bare name of the file, eg 'home' rather than
> 'home.php'. I
> then went to each function containing either a DB query (ore one which
> calls
> another DB-related function. I did a global search and replace for the
> function name 'func(' replaced by 'func($pg,'. I use Dreamweaver so
> this was
> fairly straightforward.
>
> It worked for me, but now someone is about to show me a quicker,
> cleaner
> way, aren't they?
FIRST LINES OF CODE:
<?php
function error_handler($code, $message, $file, $line, $context){
die("ERROR: $message ($code) in $file:$line");
}
set_error_handler('error_handler');
?>
Anywhere else in your code:
[examples]
$connection = mysql_connect(...) or trigger_error("No DB access.",
E_USER_ERROR);
--
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/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
On Dec 20, 2007 7:06 PM, Robert Cummings <[EMAIL PROTECTED]> wrote:
> On Thu, 2007-12-20 at 19:54 +0000, George Pitcher wrote:
> > > On Thu, December 20, 2007 8:37 am, Christoph Boget wrote:
> > > > Let's say I have the following 3 files
> > > >
> > > > global.php
> > > > <?
> > > > function myFunc() { echo __FILE__; }
> > > > ?>
> > > >
> > > > one.php
> > > > <?
> > > > include( 'global.php' );
> > > > echo 'You are in file: ';
> > > > myFunc();
> > > > ?>
> > > >
> > > > two.php
> > > > <?
> > > > include( 'global.php' );
> > > > echo 'You are in file: ';
> > > > myFunc();
> > > > ?>
> > > >
> > > > In each case, what is echoed out for __FILE__ is global.php. Apart
> > > > from
> > > > analyzing the debug_backtrace array, is there any way that myFunc()
> > > > would
> > > > display "one.php" and "two.php" respectively?
> > >
> > > $_SERVER['PHP_SELF'] and other bits in $_SERVER have the "main" PHP
> > > filename in them.
> > >
> > > __FILE__ will always be exactly the file that it's in.
> > >
> > > In between, I think you are stuck with the debug_backtrace.
> > >
> > > NOTE:
> > > If it's for error logging or error reporting, note that trigger_error
> > > automatically passes in the file/line to the error handler.
> >
> > I'm far from being an expert, and often see more efficient ways of doing
> > things (more efficient tham my own methods). Howevr, I've just been
> dealing
> > with a similar problem.
> >
> > I have a functions file with over 400 functions (and that may be too
> many -
> > but it works). I've been adding some error reporting in to my PEAR::DB
> > queries, but wanted to know which page triggered the function. I went
> > theough my php pages and gane each one a $pg variable at the start
> > containing the bare name of the file, eg 'home' rather than 'home.php'.
> I
> > then went to each function containing either a DB query (ore one which
> calls
> > another DB-related function. I did a global search and replace for the
> > function name 'func(' replaced by 'func($pg,'. I use Dreamweaver so this
> was
> > fairly straightforward.
> >
> > It worked for me, but now someone is about to show me a quicker, cleaner
> > way, aren't they?
>
> Yes, I am.
>
> <?php
> function checkpoint()
> {
> $trace = debug_backtrace();
>
> $caller = isset( $trace[0] ) ? $trace[0] : array();
> $owner = isset( $trace[1] ) ? $trace[1] : array();
>
> $file
> = isset( $caller['file'] )
> ? $caller['file']
> : null;
>
> $class
> = isset( $owner['class'] )
> ? $owner['class']
> : null;
>
> $function
> = isset( $owner['function'] )
> ? $owner['function']
> : null;
>
> $line
> = isset( $caller['line'] )
> ? $caller['line']
> : null;
>
> $type
> = isset( $owner['type'] )
> ? $owner['type']
> : null;
>
> list( $timeSub, $time ) = explode( ' ', microtime() );
> $timeSub = ereg_replace( '^[^.]\.', '', $timeSub );
> $timeSub = substr( str_pad( $timeSub, 6, '0' ), 0, 6 );
>
> echo 'Checkpoint '
> .'['.date( 'Y-m-d H:i:s', $time ).'.'.$timeSub.']: '
> .($file === null
> ? ''
> : $file.' ')
> .($line === null
> ? ''
> : sprintf( '{%05d} ', $line ))
> .($class === null
> ? ''
> : $class.$type)
> .($function === null
> ? ''
> : $function.'()')
> .$this->nl;
> }
>
> ?>
>
incidentally, i was looking through Pear::Log today;
i stumbled upon this and thought id share:
/**
* Using debug_backtrace(), returns the file, line, and enclosing
function
* name of the source code context from which log() was invoked.
*
* @param int $depth The initial number of frames we should step
* back into the trace.
*
* @return array Array containing three strings: the filename, the
line,
* and the function name from which log() was called.
*
* @access private
* @since Log 1.9.4
*/
function _getBacktraceVars($depth)
{
/* Start by generating a backtrace from the current call (here). */
$backtrace = debug_backtrace();
/*
* If we were ultimately invoked by the composite handler, we need
to
* increase our depth one additional level to compensate.
*/
if (strcasecmp(@$backtrace[$depth+1]['class'], 'Log_composite') ==
0) {
$depth++;
}
/*
* We're interested in the frame which invoked the log() function,
so
* we need to walk back some number of frames into the backtrace.
The
* $depth parameter tells us where to start looking. We go one
step
* further back to find the name of the encapsulating function from
* which log() was called.
*/
$file = @$backtrace[$depth]['file'];
$line = @$backtrace[$depth]['line'];
$func = @$backtrace[$depth + 1]['function'];
/*
* However, if log() was called from one of our "shortcut"
functions,
* we're going to need to go back an additional step.
*/
if (in_array($func, array('emerg', 'alert', 'crit', 'err',
'warning',
'notice', 'info', 'debug'))) {
$file = @$backtrace[$depth + 1]['file'];
$line = @$backtrace[$depth + 1]['line'];
$func = @$backtrace[$depth + 2]['function'];
}
/*
* If we couldn't extract a function name (perhaps because we were
* executed from the "main" context), provide a default value.
*/
if (is_null($func)) {
$func = '(none)';
}
/* Return a 3-tuple containing (file, line, function). */
return array($file, $line, $func);
}
-nathan
--- End Message ---
--- Begin Message ---
Hello I'm building a website with a search engine.
Do you think it is more usable if the search interface had a search
button? or do you think it will be more convenient to not have button to
let the users just push "enter" to search.
I would appreciate any comment regarding this, thanks.
--- End Message ---
--- Begin Message ---
Jim Webber wrote:
Hello I'm building a website with a search engine.
Do you think it is more usable if the search interface had a search
button? or do you think it will be more convenient to not have button to
let the users just push "enter" to search.
I would appreciate any comment regarding this, thanks.
Not exactly PHP related, however..
Having the button there is an indicator that the user can do something.
Even if they simply press return, the button lets them know something
can be done.
--- End Message ---
--- Begin Message ---
On Mon, 2007-12-31 at 15:19 -0800, Jim Webber wrote:
> Hello I'm building a website with a search engine.
> Do you think it is more usable if the search interface had a search
> button? or do you think it will be more convenient to not have button to
> let the users just push "enter" to search.
>
> I would appreciate any comment regarding this, thanks.
>
The one thing I have found in building websites is that you should
always create the site to the lowest IQ. Make it simple because there
are users out there that might not know that you can hit enter (or
return) to activate a search.
That's my 2 pents worth.
--- End Message ---