php-general Digest 23 Jun 2007 20:07:11 -0000 Issue 4865
Topics (messages 257695 through 257714):
Re: generate an etag header that apache can subsequentlyuse, how?
257695 by: M. Sokolewicz
257696 by: Richard Heyes
257697 by: Jochem Maas
257709 by: Jochem Maas
Re: Problems with matrix
257698 by: Jochem Maas
path finder
257699 by: elk dolk
257700 by: Tijnema
257701 by: elk dolk
257702 by: Tijnema
257703 by: elk dolk
257704 by: Tijnema
257705 by: elk dolk
257707 by: Tijnema
Re:path finder
257706 by: elk dolk
257708 by: Tijnema
foreach() using current() strange beahvior
257710 by: Julien Pauli
257711 by: Robert Cummings
257712 by: Nathan Nobbe
257713 by: Robert Cummings
257714 by: Nathan Nobbe
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 ---
Hi Jochem,
in your post I see:
Last-Modified: Fri, 22 Jun 2007 19:20:30 GMT
and:
-rw-r--r-- 1 apache apache 11924 Jun 22 21:20 foo.jpg
Those two look like they're 2 hours off from eachother! Perhaps Apache
does some magic on the unix timestamp first?
Just a thought there.
- Tul
Jochem Maas wrote:
hi Tul,
thanks for the feedback ... can I borrow your brain for a little longer? ....
M. Sokolewicz wrote:
hey Jochem,
as far as I can see, this should work for you:
<?php
$stats = stat('/dev/shm/file');
$etag = sprintf('"%x-%x-%x"', $stats['ino'], $stats['size'],
$stats['mtime']); // lowercase hexadecimal numbers separated by dashes
header('Etag: '.$etag);
?>
this is what I thought - actually I originally used dechex() - which gave the
same output as sprintf("%x", ...) ... which is not surprising.
sidenote: I'm actually only using the modification time in the etag right now.
I figure this keeps it a little faster - there is next to no chance to
that the filemtime will change and the file will be the same and using the inode
info is silly because moving the files locally (for whatever reason) shouldn't
affect
whether a 304 can be given (imho). the fact that this may result in many files
with
identical Etags maybe incorrect but I don't see the problem as the URL (and
therefore
the local file) is going to be different.
BIG BUT: apache is not generating the same hexadecimal value for the filemtime
of a
given file as I get from the various attempts with php
for a given file I get:
apache Etag : 8e6bbb80
mtime via stat() : 1182540030
mtime via filemtime() : 1182540030
sprintf("%x") Etag : 467c20fe
dechex() Etag : 467c20fe
the http headers for the URL of the file in question are:
Date: Fri, 22 Jun 2007 23:00:13 GMT
Server: Apache
Last-Modified: Fri, 22 Jun 2007 19:20:30 GMT
Etag: "8e6bbb80"
Accept-Ranges: bytes
Content-Length: 11924
Content-Type: image/jpeg
X-lori-time-2: 1182553213537
an 'ls -l' on the file in question gives (name of file changed to protect the
innocent):
-rw-r--r-- 1 apache apache 11924 Jun 22 21:20 foo.jpg
I swear it's the same file but apache is generating the hexadecimal
representation of the
filemtime differently than a 'straight' dec2hex conversion (ala dechex() and
sprintf())
doing a hexdec() on the apache generated Etag shows that this is not a question
of mtimes being slightly off (for some reason):
hexdec("8e6bbb80") = 2389425024
I'm stumped, the comments for etag_ulong_to_hex() in the apache source even
states:
"Generate the human-readable hex representation of an unsigned long
(basically a faster version of 'sprintf("%lx")')"
I'm rather wary of the 'basically' it smells fishy to me ... rather like saying
I'm basically
a women - sure there is a resemblance, but bit of investigation will show
plenty of differences.
I have been checking with static image files (ones that go no where near a
resampling script)
and the same problem occurs.
my desk is covered in hair :-/
PS - completely offtrack but what's "X-lori-time-2" - I've noticed since not
long ago,
I have no idea what it is or what purpose it serves, and seemingly nor do the
search engines.
Assuming your apache is configured to use the inode, modification time
and filesize in its etag.
The function you attached simply converts integers of type long to
hexadecimal strings. It is not the actual function creating the etag
itself.
....
I'd like to be able to generate an Etag header in php that matches
what Apache generates, I ended up in the apache source code here:
http://svn.apache.org/viewvc/httpd/httpd/branches/2.0.x/modules/http/http_protocol.c?view=markup
....
static char *etag_ulong_to_hex(char *next, unsigned long u)
{
int printing = 0;
int shift = sizeof(unsigned long) * 8 - 4;
do {
unsigned long next_digit = ((u >> shift) & (unsigned long)0xf);
if (next_digit) {
*next++ = HEX_DIGITS[next_digit];
printing = 1;
}
else if (printing) {
*next++ = HEX_DIGITS[next_digit];
}
shift -= 4;
} while (shift);
*next++ = HEX_DIGITS[u & (unsigned long)0xf];
return next;
}
....
--- End Message ---
--- Begin Message ---
Jochem Maas wrote:
but ... I need more speed ...
Don't we all? Try these:
1. stat() is slow, try not to use it
2. Don't pass images through PHP if at all possible
3. Get Fiddler (www.fiddlertool.com) - It will let you see the HTTP
response headers. It will show what's actually being requested from
you server. Typically, images are cached by the user agent , whereas
PHP files are not.
4. Don't use mod_rewrite if at all possible
5. Recompile Apache with just the modules you need
6. Recompile PHP with just the stuff you need
NB: You can always recompile later if your needs change
7. Don't use off the shelf components when you don't need to. PEAR::DB
is one example - I was using this but then mimicked the API saving
50k of code. Quite significant if you're not using an accelerator.
--
Richard Heyes
0844 801 1072
http://www.websupportsolutions.co.uk
Knowledge Base and HelpDesk software
--- End Message ---
--- Begin Message ---
Richard Heyes wrote:
> Jochem Maas wrote:
>
>> but ... I need more speed ...
>
> Don't we all? Try these:
>
> 1. stat() is slow, try not to use it
ack.
> 2. Don't pass images through PHP if at all possible
for dynamically, resampled images:
I only do this on the initial request - php generates the image ....
after that apache+mod_rewrite spit them out.
> 3. Get Fiddler (www.fiddlertool.com) - It will let you see the HTTP
> response headers. It will show what's actually being requested from
> you server. Typically, images are cached by the user agent , whereas
> PHP files are not.
I've happily used 'tail -f access.log' and the webdeveloper toolbar and firebug
upto now. but I'll look into Fiddler.
> 4. Don't use mod_rewrite if at all possible
I need mod_rewrite.
> 5. Recompile Apache with just the modules you need
this is a tough one - I don't know most of the apache modules, find out
which ones I'm actually using is a time consuming task.
> 6. Recompile PHP with just the stuff you need
> NB: You can always recompile later if your needs change
> 7. Don't use off the shelf components when you don't need to. PEAR::DB
> is one example - I was using this but then mimicked the API saving
> 50k of code. Quite significant if you're not using an accelerator.
pretty much everything I run is handmade. the page scripts on the server/sites
in question are outputting at 50-250ms - so that pretty good - it's the tons of
images and other stuff (e.g. google maps api js) that's killing the page load
time.
I use the latest version of APC (thanks to Greg Beaver for the help on setting
up a 'custom' PEAR install) with 'stat check' turned off.
still leaves me with the Etag weirdness.
>
--- End Message ---
--- Begin Message ---
M. Sokolewicz wrote:
> Hi Jochem,
>
> in your post I see:
> Last-Modified: Fri, 22 Jun 2007 19:20:30 GMT
>
> and:
>
> -rw-r--r-- 1 apache apache 11924 Jun 22 21:20 foo.jpg
>
> Those two look like they're 2 hours off from eachother! Perhaps Apache
> does some magic on the unix timestamp first?
I noticed it too - I tested Etag generation with filemtime - 2 hours and
that didn't give me anything near the result apache is generating (neither
did '+ 2 hours' btw :-).
additionally I checked with the values for FileSize and Inode and php is giving
identical values for those.
the filemtime differences must be due simply to timezone differences -
if I run the value of the Last-Modified header for any given image file through
strtotime() (on the server in question) I get the exact same integer as I do
when
I run filemtime() on the image file in question.
what the frak is apache using for the file modification time?
>
> Just a thought there.
> - Tul
>
> Jochem Maas wrote:
>> hi Tul,
>>
>> thanks for the feedback ... can I borrow your brain for a little
>> longer? ....
>>
>> M. Sokolewicz wrote:
>>> hey Jochem,
>>> as far as I can see, this should work for you:
>>> <?php
>>> $stats = stat('/dev/shm/file');
>>> $etag = sprintf('"%x-%x-%x"', $stats['ino'], $stats['size'],
>>> $stats['mtime']); // lowercase hexadecimal numbers separated by dashes
>>> header('Etag: '.$etag);
>>> ?>
>>
>> this is what I thought - actually I originally used dechex() - which
>> gave the
>> same output as sprintf("%x", ...) ... which is not surprising.
>>
>> sidenote: I'm actually only using the modification time in the etag
>> right now.
>> I figure this keeps it a little faster - there is next to no chance to
>> that the filemtime will change and the file will be the same and using
>> the inode
>> info is silly because moving the files locally (for whatever reason)
>> shouldn't affect
>> whether a 304 can be given (imho). the fact that this may result in
>> many files with
>> identical Etags maybe incorrect but I don't see the problem as the URL
>> (and therefore
>> the local file) is going to be different.
>>
>> BIG BUT: apache is not generating the same hexadecimal value for the
>> filemtime of a
>> given file as I get from the various attempts with php
>>
>> for a given file I get:
>>
>> apache Etag : 8e6bbb80
>> mtime via stat() : 1182540030
>> mtime via filemtime() : 1182540030
>> sprintf("%x") Etag : 467c20fe
>> dechex() Etag : 467c20fe
>>
>> the http headers for the URL of the file in question are:
>>
>> Date: Fri, 22 Jun 2007 23:00:13 GMT
>> Server: Apache
>> Last-Modified: Fri, 22 Jun 2007 19:20:30 GMT
>> Etag: "8e6bbb80"
>> Accept-Ranges: bytes
>> Content-Length: 11924
>> Content-Type: image/jpeg
>> X-lori-time-2: 1182553213537
>>
>> an 'ls -l' on the file in question gives (name of file changed to
>> protect the innocent):
>>
>> -rw-r--r-- 1 apache apache 11924 Jun 22 21:20 foo.jpg
>>
>> I swear it's the same file but apache is generating the hexadecimal
>> representation of the
>> filemtime differently than a 'straight' dec2hex conversion (ala
>> dechex() and sprintf())
>>
>> doing a hexdec() on the apache generated Etag shows that this is not a
>> question
>> of mtimes being slightly off (for some reason):
>>
>> hexdec("8e6bbb80") = 2389425024
>>
>> I'm stumped, the comments for etag_ulong_to_hex() in the apache source
>> even states:
>>
>> "Generate the human-readable hex representation of an unsigned long
>> (basically a faster version of 'sprintf("%lx")')"
>>
>> I'm rather wary of the 'basically' it smells fishy to me ... rather
>> like saying I'm basically
>> a women - sure there is a resemblance, but bit of investigation will
>> show plenty of differences.
>>
>> I have been checking with static image files (ones that go no where
>> near a resampling script)
>> and the same problem occurs.
>>
>>
>>
>>
>> my desk is covered in hair :-/
>>
>> PS - completely offtrack but what's "X-lori-time-2" - I've noticed
>> since not long ago,
>> I have no idea what it is or what purpose it serves, and seemingly nor
>> do the search engines.
>>
>>> Assuming your apache is configured to use the inode, modification time
>>> and filesize in its etag.
>>>
>>> The function you attached simply converts integers of type long to
>>> hexadecimal strings. It is not the actual function creating the etag
>>> itself.
>>
>> ....
>>
>>>> I'd like to be able to generate an Etag header in php that matches
>>>> what Apache generates, I ended up in the apache source code here:
>>>>
>>>> http://svn.apache.org/viewvc/httpd/httpd/branches/2.0.x/modules/http/http_protocol.c?view=markup
>>>>
>>>>
>>>>
>>
>> ....
>>
>>>> static char *etag_ulong_to_hex(char *next, unsigned long u)
>>>> {
>>>> int printing = 0;
>>>> int shift = sizeof(unsigned long) * 8 - 4;
>>>> do {
>>>> unsigned long next_digit = ((u >> shift) & (unsigned long)0xf);
>>>> if (next_digit) {
>>>> *next++ = HEX_DIGITS[next_digit];
>>>> printing = 1;
>>>> }
>>>> else if (printing) {
>>>> *next++ = HEX_DIGITS[next_digit];
>>>> }
>>>> shift -= 4;
>>>> } while (shift);
>>>> *next++ = HEX_DIGITS[u & (unsigned long)0xf];
>>>> return next;
>>>> }
>>>>
>>
>> ....
>
--- End Message ---
--- Begin Message ---
Andres Rojas wrote:
> Hi all,
>
> I'm new in PHP programming and I have a problem with this script. I need
> to read a large file around 2Mb and several lines (28000). All start Ok,
> but suddenly the script stop without message error.
1. check your error log (apache error log probably)
2. check phpinfo() for what your memory limit is
3. how many 'lines' are output before the script dies?
it seems very much like your hitting the set memory limit.
have you tried running the script from the cmdline? (cmdline php does
have a memory limit set by default)
at the *very* least your going to use 4 Megs for the data (2M for the
and 2M for the data your sticking in the $mday (etc) arrays - thats on top
of the base memory overhead and overhead for the underlying variable structures
themselves.
>
> <?php
> $fichero="62007lg.txt";
> $buffer = file($fichero);
> $lineas = count($buffer);
>
> foreach($buffer as $linea){
>
> list($day, $month, $year, $hour, $min, $temp, $hum, $dew, $baro,
> $wind, $gust, $wdir, $rlastm, $rdai, $rmon, $ryear,
> $heat)=sscanf($linea,"%d %d %d %d %d %f %d %f %f %d %d %d %f %f %f %f %f \n");
>
> $mday[]=$day;
> $mmonth[]=$month;
> $myear[]=$year;
> $mhour[]=$hour;
> $mmin[]=$min;
> $mtemp[]=$temp;
> $mhum[]=$hum;
> $mdew[]=$dew;
> $mbaro[]=$baro;
> $mwind[]=$wind;
> $mgust[]=$gust;
> $mwdir[]=$wdir;
> $mrlastm[]=$rlastm;
> $mdai[]=$rdai;
> $mrmon[]=$rmon;
> $mryear[]=$ryear;
> $mheat[]=$heat;
> echo"$day $month $year $hour $min $temp $hum $dew $baro $wind $gust
> $wdir $rlastm $rdai $rmon $ryear $heat <br>";
> }
>
> ?>
>
> If only I print the variable $buffer all it's ok, but when I try to fill
> all the matrix the script doesn't work. If I reduce the number of matrix
> only a 3 o 4 it's Ok, but If I increase number of this matrix the script
> crash again.
>
> Perhaps it's a problem of memory of server, but my service provider say
> me that this is not the problem.
>
>
> Thank you very much
>
--- End Message ---
--- Begin Message ---
Hi all,
When I test my photo album in my IIS testing server relative path in the
following code works fine :
echo "<div class='cccc'><img src='/img/{$photoFileName}' width='120'
height='160' border='0' /></div> ";
but when I upload it to the web server I dont see my photos, my /home
directory on the web server contains
public_ftp and public_html where my web site is stored I modify the path to
this :
echo "<div class='cccc'><img src='/home/public_html/img/{$photoFileName}'
width='120' height='160' border='0' /></div> ";
it doesnt function
please comment
---------------------------------
Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel
and lay it on us.
--- End Message ---
--- Begin Message ---
On 6/23/07, elk dolk <[EMAIL PROTECTED]> wrote:
Hi all,
When I test my photo album in my IIS testing server relative path in the
following code works fine :
echo "<div class='cccc'><img src='/img/{$photoFileName}' width='120' height='160'
border='0' /></div> ";
but when I upload it to the web server I don't see my photos, my /home
directory on the web server contains
public_ftp and public_html where my web site is stored I modify the path to
this :
echo "<div class='cccc'><img src='/home/public_html/img/{$photoFileName}' width='120'
height='160' border='0' /></div> ";
it doesn't function
please comment
/home/..... is the path on your filesystem, not the path you should
use in your URL.
The code you used on your IIS testing server should work fine.
Tijnema
--
Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info
--- End Message ---
--- Begin Message ---
On 6/23/07, elk dolk <[EMAIL PROTECTED]> wrote:
> Hi all,
> When I test my photo album in my IIS testing server relative path in the
> following
> code works fine :
> echo "<div class='cccc'><img src='/img/{$photoFileName}' width='120'
> height='160'
border='0' /></div> ";
> but when I upload it to the web server I don't see my photos, my /home
> directory on
> the web server contains
> public_ftp and public_html where my web site is stored I modify the path
> to this :
> echo "<div class='cccc'><img src='/home/public_html/img/{$photoFileName}'
> width='120' height='160' border='0' /></div> ";
> it doesn't function
> please comment
-------------------------------------------------------------
/home/..... is the path on your filesystem, not the path you should
use in your URL.
The code you used on your IIS testing server should work fine.
-------------------------------------------------------------
no it does not work !
---------------------------------
Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel
and lay it on us.
--- End Message ---
--- Begin Message ---
On 6/23/07, elk dolk <[EMAIL PROTECTED]> wrote:
On 6/23/07, elk dolk <[EMAIL PROTECTED]> wrote:
> Hi all,
> When I test my photo album in my IIS testing server relative path in the
following
> code works fine :
> echo "<div class='cccc'><img src='/img/{$photoFileName}' width='120'
height='160'
border='0' /></div> ";
> but when I upload it to the web server I don't see my photos, my /home
directory on
> the web server contains
> public_ftp and public_html where my web site is stored I modify the path
to this :
> echo "<div class='cccc'><img src='/home/public_html/img/{$photoFileName}'
> width='120' height='160' border='0' /></div> ";
> it doesn't function
> please comment
-------------------------------------------------------------
/home/..... is the path on your filesystem, not the path you should
use in your URL.
The code you used on your IIS testing server should work fine.
-------------------------------------------------------------
no it does not work !
Hmm, try full URL to the images, like this:
echo "<div class='cccc'><img
src='http://www.mydomain.com/something/img/{$photoFileName}'
width='120' height='160' border='0' /></div> ";
Also, make sure that you can see the photos when going to
http://www.mydomain.com/something/img/the_name_of_a_photo.ext
Tijnema
--
Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info
--- End Message ---
--- Begin Message ---
On 6/23/07, elk dolk <[EMAIL PROTECTED]> wrote:
>
> On 6/23/07, elk dolk <[EMAIL PROTECTED]> wrote:
> > Hi all,
> > When I test my photo album in my IIS testing server relative path in the
> > following
> > code works fine :
>
> > echo "<div class='cccc'><img src='/img/{$photoFileName}' width='120'
> > height='160'
> border='0' /></div> ";
>
> > but when I upload it to the web server I don't see my photos, my /home
> > directory
on
> > the web server contains
>
> > public_ftp and public_html where my web site is stored I modify the path
> > to this :
>
> > echo "<div class='cccc'><img src='/home/public_html/img/{$photoFileName}'
> > width='120' height='160' border='0' /></div> ";
> > it doesn't function
>
> > please comment
> -------------------------------------------------------------
> /home/..... is the path on your filesystem, not the path you should
> use in your URL.
> The code you used on your IIS testing server should work fine.
> -------------------------------------------------------------
> no it does not work !
>
----------------------------------------------------------
>Hmm, try full URL to the images, like this:
echo "<div class='cccc'><img
src='http://www.mydomain.com/something/img/{$photoFileName}'
width='120' height='160' border='0' /></div> ";
it does not function as well!
----------------------------------------------------------
>Also, make sure that you can see the photos when going to
http://www.mydomain.com/something/img/the_name_of_a_photo.ext
this is O.K. I can see my photos does it tell you something?
---------------------------------
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
--- End Message ---
--- Begin Message ---
On 6/23/07, elk dolk <[EMAIL PROTECTED]> wrote:
On 6/23/07, elk dolk <[EMAIL PROTECTED]> wrote:
>
> On 6/23/07, elk dolk <[EMAIL PROTECTED]> wrote:
> > Hi all,
> > When I test my photo album in my IIS testing server relative path in the
following
> > code works fine :
>
> > echo "<div class='cccc'><img src='/img/{$photoFileName}' width='120'
height='160'
> border='0' /></div> ";
>
> > but when I upload it to the web server I don't see my photos, my /home
directory
on
> > the web server contains
>
> > public_ftp and public_html where my web site is stored I modify the path
to this :
>
> > echo "<div class='cccc'><img src='/home/public_html/img/{$photoFileName}'
> > width='120' height='160' border='0' /></div> ";
> > it doesn't function
>
> > please comment
> -------------------------------------------------------------
> /home/..... is the path on your filesystem, not the path you should
> use in your URL.
> The code you used on your IIS testing server should work fine.
> -------------------------------------------------------------
> no it does not work !
>
----------------------------------------------------------
>Hmm, try full URL to the images, like this:
echo "<div class='cccc'><img
src='http://www.mydomain.com/something/img/{$photoFileName}'
width='120' height='160' border='0' /></div> ";
it does not function as well!
So, when you go to the page with this code, you see one of more [X]
right? What do you see when you right click on one of them and click
properties?
Do you see the url to the image? or are there some kind of weird
tokens in the URL?
----------------------------------------------------------
>Also, make sure that you can see the photos when going to
http://www.mydomain.com/something/img/the_name_of_a_photo.ext
this is O.K. I can see my photos does it tell you something?
Yes, I know that you're images are at the correct place and that they
are viewable from outside.
Tijnema
--
Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info
--- End Message ---
--- Begin Message ---
> > On 6/23/07, elk dolk <[EMAIL PROTECTED]> wrote:
> > > Hi all,
> > > When I test my photo album in my IIS testing server relative path in the
following
> > > code works fine :
> >
> > > echo "<div class='cccc'><img src='/img/{$photoFileName}' width='120'
height='160'
> > border='0' /></div> ";
> >
> > > but when I upload it to the web server I don't see my photos, my /home
directory
> on
> > > the web server contains
> >
> > > public_ftp and public_html where my web site is stored I modify the
> > > path to this
:
> >
> > > echo "<div class='cccc'><img
> > > src='/home/public_html/img/{$photoFileName}'
> > > width='120' height='160' border='0' /></div> ";
> > > it doesn't function
> >
> > > please comment
> > -------------------------------------------------------------
> > /home/..... is the path on your filesystem, not the path you should
> > use in your URL.
> > The code you used on your IIS testing server should work fine.
> > -------------------------------------------------------------
> > no it does not work !
> >
> ----------------------------------------------------------
> >Hmm, try full URL to the images, like this:
> echo "<div class='cccc'><img
> src='http://www.mydomain.com/something/img/{$photoFileName}'
> width='120' height='160' border='0' /></div> ";
>
> it does not function as well!
>So, when you go to the page with this code, you see one of more [X]
right? What do you see when you right click on one of them and click
properties?
>Do you see the url to the image? or are there some kind of weird
tokens in the URL?
----------------------------------------------------------
Sorry I have to correct it the above path works :
img
> src='http://www.mydomain.com/something/img/{$photoFileName}'
but I can see some of my photos! and when I right click on them
I see the properties : url://mydomain/img/26.jpg
size 2976 bytes
dim 120x160
when I right click on [X]s I see the url also, only the size is not available!
> ----------------------------------------------------------
> >Also, make sure that you can see the photos when going to
> http://www.mydomain.com/something/img/the_name_of_a_photo.ext
>
> this is O.K. I can see my photos does it tell you something?
>Yes, I know that you're images are at the correct place and that they
are viewable from outside.
---------------------------------
Need a vacation? Get great deals to amazing places on Yahoo! Travel.
--- End Message ---
--- Begin Message ---
On 6/23/07, elk dolk <[EMAIL PROTECTED]> wrote:
> > On 6/23/07, elk dolk <[EMAIL PROTECTED]> wrote:
> > > Hi all,
> > > When I test my photo album in my IIS testing server relative path in the
following
> > > code works fine :
> >
> > > echo "<div class='cccc'><img src='/img/{$photoFileName}' width='120'
height='160'
> > border='0' /></div> ";
> >
> > > but when I upload it to the web server I don't see my photos, my /home
directory
> on
> > > the web server contains
> >
> > > public_ftp and public_html where my web site is stored I modify the
path to this
:
> >
> > > echo "<div class='cccc'><img
src='/home/public_html/img/{$photoFileName}'
> > > width='120' height='160' border='0' /></div> ";
> > > it doesn't function
> >
> > > please comment
> > -------------------------------------------------------------
> > /home/..... is the path on your filesystem, not the path you should
> > use in your URL.
> > The code you used on your IIS testing server should work fine.
> > -------------------------------------------------------------
> > no it does not work !
> >
> ----------------------------------------------------------
> >Hmm, try full URL to the images, like this:
> echo "<div class='cccc'><img
> src='http://www.mydomain.com/something/img/{$photoFileName}'
> width='120' height='160' border='0' /></div> ";
>
> it does not function as well!
>So, when you go to the page with this code, you see one of more [X]
right? What do you see when you right click on one of them and click
properties?
>Do you see the url to the image? or are there some kind of weird
tokens in the URL?
----------------------------------------------------------
Sorry I have to correct it the above path works :
img
> src='http://www.mydomain.com/something/img/{$photoFileName}'
but I can see some of my photos! and when I right click on them
I see the properties : url://mydomain/img/26.jpg
size 2976 bytes
dim 120x160
when I right click on [X]s I see the url also, only the size is not available!
Are you sure the photo is actually there? What happens if you copy the
URL of one of the [X] and place it in your browser? Does it display
you the photo?
And if you refresh, are the same photos missing each time? or is it
different each refresh?
Tijnema
--
Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info
--- End Message ---
--- Begin Message ---
> Sorry I have to correct it the above path works :
> img
> > src='http://www.mydomain.com/something/img/{$photoFileName}'
> but I can see some of my photos! and when I right click on them
> I see the properties : url://mydomain/img/26.jpg
> size 2976 bytes
> dim 120x160
>
> when I right click on [X]s I see the url also, only the size is not available!
>
Are you sure the photo is actually there? What happens if you copy the
URL of one of the [X] and place it in your browser? Does it display
you the photo?
And if you refresh, are the same photos missing each time? or is it
different each refresh?
---------------------------------------------------------
Yes the photos are there.If I copy the url to my browser I can see them and
when I refresh the same photos are missing!
---------------------------------
Be a better Heartthrob. Get better relationship answers from someone who knows.
Yahoo! Answers - Check it out.
--- End Message ---
--- Begin Message ---
On 6/23/07, elk dolk <[EMAIL PROTECTED]> wrote:
> Sorry I have to correct it the above path works :
> img
> > src='http://www.mydomain.com/something/img/{$photoFileName}'
> but I can see some of my photos! and when I right click on them
> I see the properties : url://mydomain/img/26.jpg
> size 2976 bytes
> dim 120x160
>
> when I right click on [X]s I see the url also, only the size is not available!
>
Are you sure the photo is actually there? What happens if you copy the
URL of one of the [X] and place it in your browser? Does it display
you the photo?
And if you refresh, are the same photos missing each time? or is it
different each refresh?
---------------------------------------------------------
Yes the photos are there.If I copy the url to my browser I can see them and
when I refresh the same photos are missing!
Well, seems like a client side problem.. Try different browser, cleaning cache,
Well, this has nothing to do with your PHP code, if you still need
help with this, contact me offlist with the URL of your site.
Tijnema
--
Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info
--- End Message ---
--- Begin Message ---
Please consider this code :
<?php
$a = array("One","Two","Three");
foreach ($a AS $k=>$v) {
}
var_dump(current($a));
// outputs boll(false);
that's expected as foreach moves the internal array pointer, it's
documented.
now consider this :
<?php
$a = array("One","Two","Three");
foreach ($a AS $k=>$v) {
current($a);
}
var_dump(current($a));
// outputs string("One");
When using the internal pointer just by calling current() (so not moving
it), the output of the foreach loop has changed ...
Can someone explain that ?
regards.
--- End Message ---
--- Begin Message ---
On Sat, 2007-06-23 at 19:15 +0200, Julien Pauli wrote:
> Please consider this code :
>
> <?php
> $a = array("One","Two","Three");
>
> foreach ($a AS $k=>$v) {
> }
>
> var_dump(current($a));
> // outputs boll(false);
>
> that's expected as foreach moves the internal array pointer, it's
> documented.
>
> now consider this :
>
> <?php
> $a = array("One","Two","Three");
>
> foreach ($a AS $k=>$v) {
> current($a);
> }
>
> var_dump(current($a));
> // outputs string("One");
>
> When using the internal pointer just by calling current() (so not moving
> it), the output of the foreach loop has changed ...
> Can someone explain that ?
The answers lies in the following although it's not terribly clear why
the behaviour is as it is:
****
Note: Unless the array is referenced, foreach operates on a copy of the
specified array and not the array itself. Therefore, the array pointer
is not modified as with the each() construct, and changes to the array
element returned are not reflected in the original array. However, the
internal pointer of the original array is advanced with the processing
of the array. Assuming the foreach loop runs to completion, the array's
internal pointer will be at the end of the array.
****
If you understand how PHP copies values then it makes sense. Let me
explain... When the foreach loop is entered $a is copied for use by the
foreach itrator; however, a copy in PHP is a lazy copy. This means that
the the copy is still referencing the original value, and this is why
the internal pointer is still advanced.
Now what probably happens is that when the current() function is used on
$a something internally tells the PHP engine that a modification has
occurred, as such the COW (copy on write) policy comes into effect. This
essentially differentiates a copy since a change is occurring such that
there is now a real and distinct copy. So internally $a had the internal
pointer reset on entry to the foreach loop, current() somehow invokes
the COW policy causing a real copy to be generated, and then the foreach
continues merrily forward with the real copy leaving current() to work
with the original copy. Hope that make sense to you :)
For what it's worth, COW is why if you have a variable consuming 100
megabytes stored in $x and you assign it to $y that you don't end up
consuming 200 megs of memory. Now if $x is a string and you change
append one character to $y, you should find that now you are consuming
200 megs of memory since a real copy is generated when the change is
incurred. This is an optimization strategy.
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--- End Message ---
--- Begin Message ---
Julien,
i reproduced your experiment and got a different result on the first one. i
found that the internal pointer does not seem to be affected if there is a
check on the index of the internal pointer during iteration, but if there is
no check on the index during iteration the
pointer seems to get incremented. needless to say this is rather strange. *
*also *turadg at berkeley dot edu* describes his experience w/ this issue on
the foreach
documentation<http://www.php.net/manual/en/control-structures.foreach.php>in
the user comments section. he found that by aliasing the original
array
variable the behavior described in the documentation is realized.
i have summarized these findings in the following code segment, which you
can run yourself as well for corroboration
<?php
/// initialize $a to an array w/ 3 strings
$a = array('one', 'two', 'three');
echo 'experiment 1a.' . PHP_EOL;
/// iterate over a checking the value of the internal pointer during each
iteration
foreach($a as $k => $v) {
if(current($a) != false) {
echo current($a) . PHP_EOL;
} else {
var_dump(current($a));
}
}
/// check the internal pointer after iteration is complete (should be
pointing at last index)
if(current($a) != false) { // strangely this is still the first index of the
array
echo current($a) . PHP_EOL;
} else {
var_dump(current($a));
}
echo 'experiment 1b.' . PHP_EOL;
/// another run through the array where there is no check on the value of
the internal pointer during each iteration
foreach($a as $k => $v) {}
/// check the internal pointer after iteration this time
if(current($a) != false) { // and now the pointer is the last index of the
array (as expected)
echo current($a) . PHP_EOL;
} else {
var_dump(current($a));
}
echo 'experiment 2a.' . PHP_EOL;
//// ALIAS THE ORIGINAL ARRAY VARIABLE
$a2 =& $a; // create an alias of $a for further experimentation
foreach($a as $k => $v) { // first experiment
if(current($a) != false) { // now the internal index is being incremented
echo current($a) . PHP_EOL;
} else {
var_dump(current($a));
}
}
if(current($a) != false) { // and here the internal pointer is the last
index
echo current($a) . PHP_EOL;
} else {
var_dump(current($a));
}
echo 'experiment 2b.' . PHP_EOL;
/// second experiment (no checking of the index during iteration)
foreach($a as $k => $v) {}
if(current($a) != false) { // and the internal pointer is the last index
echo current($a) . PHP_EOL;
} else {
var_dump(current($a));
}
?>
/// this is the output on my machine
experiment 1a.
one
one
one
one
experiment 1b.
bool(false)
experiment 2a.
two
three
bool(false)
bool(false)
experiment 2b.
bool(false)
in summary, COW or not; i think the documentation could be revised a bit to
clarify these subtleties.
-nathan
On 6/23/07, Julien Pauli <[EMAIL PROTECTED]> wrote:
Please consider this code :
<?php
$a = array("One","Two","Three");
foreach ($a AS $k=>$v) {
}
var_dump(current($a));
// outputs boll(false);
that's expected as foreach moves the internal array pointer, it's
documented.
now consider this :
<?php
$a = array("One","Two","Three");
foreach ($a AS $k=>$v) {
current($a);
}
var_dump(current($a));
// outputs string("One");
When using the internal pointer just by calling current() (so not moving
it), the output of the foreach loop has changed ...
Can someone explain that ?
regards.
--- End Message ---
--- Begin Message ---
On Sat, 2007-06-23 at 15:15 -0400, Nathan Nobbe wrote:
>
> in summary, COW or not; i think the documentation could be revised a bit to
> clarify these subtleties.
Regardless of additional documentation or not, I think it's rather poor
choice of programming style to mix the foreach construct with the older,
lower level, internal array manipulation and probing functions. I think
that is what should be documented since you just might get weird
results :)
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--- End Message ---
--- Begin Message ---
On 6/23/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
Regardless of additional documentation or not, I think it's rather poor
choice of programming style to mix the foreach construct with the older,
lower level, internal array manipulation and probing functions. I think
that is what should be documented since you just might get weird
results :)
i agree; at least i have never had a need to determine the current index of
the internal array pointer in nearly 3 years working w/ php.
although it is somewhat interesting to experiment w/ the language to see how
it behaves :)
-nathan
On 6/23/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
On Sat, 2007-06-23 at 15:15 -0400, Nathan Nobbe wrote:
>
> in summary, COW or not; i think the documentation could be revised a bit
to
> clarify these subtleties.
Regardless of additional documentation or not, I think it's rather poor
choice of programming style to mix the foreach construct with the older,
lower level, internal array manipulation and probing functions. I think
that is what should be documented since you just might get weird
results :)
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--- End Message ---