Connecting Tech Pros Worldwide Help | Site Map

is_null very slow

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 01:30 PM
Peter Croft
Guest
 
Posts: n/a
Default is_null very slow

I am a newcomer to php; I recently loaded a binary copy (5.0.3) onto my PC
running win2k and Apache 2.0.52.
It seems to work fine except that it is very slow running the function
is_null e.g. the dummy program below -
<?php
for($i=0; $i<1000; $i++) {
if(is_null($x)) $y=0;
}
echo 'done'
?>
This takes around 30 seconds to run and the disk is accessed continuously.
A friend ran it under both win2k and Linux and it finished in under a
second. Have I set up something wrong? As I say everything else seems fine.
Thanks for any help.
Peter Croft



  #2  
Old July 17th, 2005, 01:30 PM
Andy Hassall
Guest
 
Posts: n/a
Default Re: is_null very slow

On Wed, 8 Jun 2005 22:11:55 +0100, "Peter Croft"
<peter_croft@textandvideo.co.uk> wrote:
[color=blue]
>I am a newcomer to php; I recently loaded a binary copy (5.0.3) onto my PC
>running win2k and Apache 2.0.52.
>It seems to work fine except that it is very slow running the function
>is_null e.g. the dummy program below -
><?php
>for($i=0; $i<1000; $i++) {
> if(is_null($x)) $y=0;
> }
>echo 'done'
>?>
>This takes around 30 seconds to run and the disk is accessed continuously.
>A friend ran it under both win2k and Linux and it finished in under a
>second. Have I set up something wrong? As I say everything else seems fine.[/color]

That would produce 1000 warnings under a sensible error_reporting
configuration.

Perhaps your copy is logging warnings to a file, whereas your friend's has
error reporting disabled entirely.

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
  #3  
Old July 17th, 2005, 01:30 PM
Peter Croft
Guest
 
Posts: n/a
Default Re: is_null very slow

Thanks - that seems to be the answer.
I see I misunderstood is_null. What I was trying to do was to find which
values in an array had not been assigned to
and then give them a value
(It is more convenient for me to do things this way than to assign default
values to start with.)
e.g.
$x[0]=1;
$x[101]=22;
for($i=0; $i<1000; $i++) {
if(is_null($x[$i])) $x[$i]=$i;
}
I have just read about isset - is that the right way to do it?
To a php-newbie it seems a bit strange that some elements in an array can be
considered undefined whilst others aren't.
Cheers,
Peter



"Andy Hassall" <andy@andyh.co.uk> wrote in message
news:08oea15ohcgacho64ngn45e06kg1vpouv2@4ax.com...[color=blue]
> On Wed, 8 Jun 2005 22:11:55 +0100, "Peter Croft"
> <peter_croft@textandvideo.co.uk> wrote:
>[color=green]
> >I am a newcomer to php; I recently loaded a binary copy (5.0.3) onto my[/color][/color]
PC[color=blue][color=green]
> >running win2k and Apache 2.0.52.
> >It seems to work fine except that it is very slow running the function
> >is_null e.g. the dummy program below -
> ><?php
> >for($i=0; $i<1000; $i++) {
> > if(is_null($x)) $y=0;
> > }
> >echo 'done'
> >?>
> >This takes around 30 seconds to run and the disk is accessed[/color][/color]
continuously.[color=blue][color=green]
> >A friend ran it under both win2k and Linux and it finished in under a
> >second. Have I set up something wrong? As I say everything else seems[/color][/color]
fine.[color=blue]
>
> That would produce 1000 warnings under a sensible error_reporting
> configuration.
>
> Perhaps your copy is logging warnings to a file, whereas your friend's[/color]
has[color=blue]
> error reporting disabled entirely.
>
> --
> Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool[/color]



  #4  
Old July 17th, 2005, 01:30 PM
Peter Fox
Guest
 
Posts: n/a
Default Re: is_null very slow

Following on from Peter Croft's message. . .[color=blue]
>To a php-newbie it seems a bit strange that some elements in an array can be
>considered undefined whilst others aren't.[/color]

You often find empty building plots in a street.

Some houses are vacant. - $house[67]=0;

Some may not be built or have been demolished.
- unset($house[45])


--
PETER FOX Not the same since the e-commerce business came to a .
peterfox@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
  #5  
Old July 17th, 2005, 01:30 PM
cyberhorse
Guest
 
Posts: n/a
Default Re: is_null very slow

Why don't you use isset() or empty() instead then?

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.