OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
php-general Digest 2 Apr 2008 06:49:25 -0000 Issue 5381

php-general-digest-helplists.php.net
Date: Wed Apr 02 2008 - 01:49:25 CDT


php-general Digest 2 Apr 2008 06:49:25 -0000 Issue 5381

Topics (messages 272424 through 272429):

Re: April Fools Easter Egg
        272424 by: Zoltán Németh

autoload with namespace
        272425 by: Ryan Panning

how to possibly cache something and the theory of better performance / better speed
        272426 by: Joey
        272427 by: Robert Cummings
        272428 by: Chris

Re: array with null shows different with print_r and var_dump
        272429 by: Sanjay Mantoor

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


Ray Hauge írta:
> tedd wrote:
>> At 9:23 AM -0500 4/1/08, Ray Hauge wrote:
>>> Don't forget to check your phpinfo() page for the annual easter egg.
>>>
>>> --
>>> Ray Hauge
>>> www.primateapplications.com
>>
>>
>> You got me.
>>
>> Cheers,
>>
>> tedd
>>
>
> Here's the image that I see on PHP 5.1.0. My 5.2.5 site has a distorted
> image instead of the dog.
>
> 5.1.0:
> http://www.primateapplications.com/info.php.gif
>
> 5.2.5:
> http://www.primateapplications.com/info.php
>

same here, distorted image on 5.2.5 and dog on 5.1.2 :)

greets,
Zoltán Németh

attached mail follows:


I haven't been keeping an eye on this list so if this has come up before
please point me in the right direction. :)

Playing around with dev PHP 5.3 and namespaces, I'm finding it hard to
write an autoload function. Since autoload will be triggered on any
namespace call, the request could be for a namespace function or
constant. Ex:

FOO::BAR::me() ## A namespace function or class static function?
FOO::BAR::ME ## A namespace constant or class constant?

Since there isn't really a way for PHP to know what it is looking for,
what would be a good method to write the autoload? Assuming the file
structure:

- Namespaces are in separate directories NS1::NS2::Class1 ==
NS1/NS2/class.Calss1.php
- Namespace files and class files are prefixed with ns.*.php and
class.*.php (respectively)

attached mail follows:


Hi All,

 

This is 2 parts, first "theory"

 

I found this code on the web tossed it into a site to test it and it seems
pretty efficient. Sometimes when sites are small without a lot of traffic
efficiency isn't a big issue and a lot of people don't pay attention to
these details. I just like keeping things clean and efficient so here goes
the theory part.

 

I used to use a script to grab a random image from a folder of images by
scanning the folder, returning the list of images, getting one of them
randomly and displaying it.

This page of course had to be a .php page so everything runs through the php
engine taking some processing power to go through the regular html code in
order to run the php stuff.

 

This script used the concept of running the page as an html page and calling
the php script like so:

<img src="/images/rotate.php">

 

This would call the below .php file in order to execute the list of files in
the folder and display the random image.

 

<?php

$folder = '';

$exts = 'jpg jpeg png gif';

 

$files = array(); $i = -1;

if ('' == $folder) $folder = './';

 

$handle = opendir($folder);

$exts = explode(' ', $exts);

 

while (false !== ($file = readdir($handle))) {

  foreach($exts as $ext) {

    if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg,
case insensitive

      $files[] = $file;

      ++$i;

    }

  }

}

 

closedir($handle);

mt_srand((double)microtime()*1000000);

$rand = mt_rand(0, $i);

header('Location: '.$folder.$files[$rand]);

?>

 

 

Conceptually that seems to make it a little more efficient.

Does everyone agree?

 

 

OK now, getting greedy I want to take it to another level. Instead of
having to read the folder for images every time, why not read the image
names into a file so that we can maintain therbey caching the list. This is
based on 25-30 images in the folder you might even have more. Since in this
case we're not going to add images too often, then we can upload the images
delete the cache list and a new one will be generated hopefully saving time
for all future executions.

 

We would also have to modify the above code to check if the file exists, if
not generate the file and if it's there just display the images.

 

Assuming only 25-30 images am I splitting hairs here? Does this make sense?
Of course if I have 200 pictures, then this is the way to go but would this
really make a difference?

 

Thanks!

 

Joey

 

 

 

 

 

attached mail follows:


On Wed, 2008-04-02 at 00:26 -0400, Joey wrote:
> Hi All,
>
> [-- SNIPPITY SNIP SNIP --]
>
> Assuming only 25-30 images am I splitting hairs here? Does this make
> sense?
> Of course if I have 200 pictures, then this is the way to go but would
> this
> really make a difference?

Randomizing the file referred to in the HTML <img /> tag is probably
faster than requesting a script that returns random image binary
content. For one, you avoid browser cache issues. Two, the browser will
cache the requested image so if it happens to be the random one in
another page request then it won't be re-downloaded. Now using the first
solution of generating a random src value for an image tag, caching the
list of image options will probably have very little effect since you
will either:

    a) have to request the cache from a database
    b) request the cache from the filesystem
    c) install and configure memcache and retrieve the cache from memory

Generally speaking, for 25 to 30 images, you're operating system will do
a good job of keeping the list in it's own cache and returning that list
very promptly when you perform opendir() and subsequent readdir()
requests.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

attached mail follows:


> I used to use a script to grab a random image from a folder of images by
> scanning the folder, returning the list of images, getting one of them
> randomly and displaying it.

Isn't that what the code is doing? Maybe I'm missing something but
you've only mentioned one method.

What's the second method to compare against?

> OK now, getting greedy I want to take it to another level. Instead of
> having to read the folder for images every time, why not read the image
> names into a file so that we can maintain therbey caching the list. This is
> based on 25-30 images in the folder you might even have more. Since in this
> case we're not going to add images too often, then we can upload the images
> delete the cache list and a new one will be generated hopefully saving time
> for all future executions.

> Assuming only 25-30 images am I splitting hairs here?

Yes. I don't think you'll notice any difference with this number, though
a quick script would tell you for certain.

$orig_image = 'logo.jpg';
$cache_folder = '/path/to/folder';
for ($i = 0; $i < 500; $i++) {
   copy($cache_folder.'/'.$orig_image, $cache_folder . '/' . $i . '.jpg');
}

> Of course if I have 200 pictures, then this is the way to go but would this
> really make a difference?

Once you get a lot of images (500? 1000? more?) it will but if you only
expect 30 there's not much point.

Using a cache file you'll need extra checks (make sure nobody slips in a
symlink to /etc/passwd or a url or something) - but you should be doing
those checks anyway.

--
Postgresql & php tutorials
http://www.designmagick.com/

attached mail follows:


Hello,

I am new to PHP and PHP community.

Following program outputs different values with print_r and var_dump.

$array = array(null, NULL);

print_r($array); prints values like below
Array
(
    [0] =>
    [1] =>
)

where as var_dump($array) prints values like below
array(2) {
  [0]=>
  NULL // Does this convert to null to NULL?
  [1]=>
  NULL
}

Can you tell me why the above difference?

--
Thanks,
Sanjay Mantoor