Re: [PHP] Re: Think I found a PHP bug

2011-12-08 Thread Rasmus Lerdorf
This is fixed in PHP 5.4 by completely dropping support for the TZ
environment variable. PHP will always use UTC unless you explicitly set
it to something. It won't matter which timezone the system is running
in. This is the only reliable way to always have consistent behaviour
across all environments.

-Rasmus

On 12/06/2011 04:46 PM, Patricia Dewald wrote:
 
 In OpenSuSE 12.1 i can reproduce this issue.
 
 My workaround is to check the correct timezone.
 
 On Tue, 15 Nov 2011 23:34:18 +0100, Geoff Shang ge...@quitelikely.com
 wrote:
 
 Hi,

 A couple of weeks ago, I discovered what I'm pretty sure is a PHP bug.
 In addition, I looked in the PHP changelog and I haven't seen any
 mention of a fix for it.

 I'm writing here because I was wondering if anyone else can confirm it
 and what to do about it.

 The bug is that if a server's timezone is set to Europe/London and you
 don't set an explicit timezone in your script, if it's winter time in
 the UK, PHP thinks the timezone is UTC instead of Europe/London.

 Example:

 First, lets confirm that the system time is in fact set to Europe/London.

 $ cmp --verbose /etc/localtime /usr/share/zoneinfo/Europe/London
 $ echo $?
 0

 Now lets see what PHP thinks it is.

 $ php -r 'echo date_default_timezone_get();'
 UTC

 What about if we set it in the environment?

 $ export TZ=Europe/London
 $ php -r 'echo date_default_timezone_get();'
 Europe/London

 OK, so we appear to have an issue.  But is this just semantics?  Well
 no. consider the following (with TZ once again unset):

 $ php -r 'echo date (r, strtotime (1 July 2011 12:00 pm'
 Fri, 01 Jul 2011 12:00:00 +

 But of course, Europe/London isn't on + in July.

 $ export TZ=Europe/London
 $ php -r 'echo date (r, strtotime (1 July 2011 12:00 pm));'
 Fri, 01 Jul 2011 12:00:00 +0100

 The problem comes in when we view times created in one and printed in
 the other:

 $ unset TZ
 $ php -r 'echo strtotime (1 July 2011 12:00 pm);'
 1309521600
 $ export TZ=Europe/London
 $ php -r 'echo date (r, 1309521600);'
 Fri, 01 Jul 2011 13:00:00 +0100

 And the opposite:

 $ export TZ=Europe/London
 $ php -r 'echo strtotime (1 July 2011 12:00 pm);'
 1309518000
 $ unset TZ
 $ php -r 'echo date (r, 1309518000);'
 Fri, 01 Jul 2011 11:00:00 +

 This last one is what led me to discover this bug.  We use automation
 software to run our Internet radio station.  The playout system is
 written in C and the web front-end is written in PHP, with the data
 they work on the only point of commonality between them.  The station
 was set up during the European summer.  When the clocks changed, the
 playout system coped but the PHP front-end was showing everything an
 hour out.

 Now of course, I personally can force the front-end to use
 Europe/London and it will work for me.  And I guess ultimately it
 would make sense to program the system to allow the user to specify a
 timezone rather than relying on the server default.  But right now it
 doesn't, and any solution would need to take the playout system into
 account.

 At any rate, none of this is the point.  If you're using the system
 default timezone, you expect it to (a) be correct and (b) be consistant.

 Note that this bug may affect other timezones which are on UTC durin
 the winter or summer, but I've not tested any other timezones as this
 would mean changing the system timezone and I'm not real keen on doing
 that on any of my systems.

 This bug was found on a Debian Squeeze system running the following
 version of PHP:

 PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011
 08:24:40)
 Copyright (c) 1997-2009 The PHP Group
 Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

 I realise this is 5.3.3 and that 5.3.8 is now out.  It's possible that
 this has been fixed but I could not find any traces of such a fix in
 the changelogs.

 I'd be interested to know if anyone else can confirm this bug and, if
 confirmed, what I should do about it.

 Thanks,
 Geoff.

 
 


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



Re: [PHP] semaphores are broken

2011-05-08 Thread Rasmus Lerdorf
On Fri, May 6, 2011 at 12:57 PM, Jeremy Greene jer...@zeevee.com wrote:
 Then I find out that sem_acquire() actually returns **OK** when the
 underlying semop call gets an EINTR!!! Holy cow. How can a php system
 call loose an error?! That's just crazy.

Generally you don't care about an EINTR on a semop() call. If you do
you will have installed a signal handler to handle that interruption.
The low-level code has:

while (semop(sem_ptr-semid, sop, 1) == -1) {
if (errno != EINTR) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, failed to %s
key 0x%x: %s, acquire ? acquire : release, sem_ptr-key,
strerror(errno));
RETURN_FALSE;
}
}

which ignores the EINTR as you can see. If you really want to get in
there to handle the uncaught interruption you can do:

pcntl_signal(SIGEINTR,  function($signo) {
 echo Interrupted\n;
});
sem_acquire(...);
pcntl_signal_dispatch();

But in general, using semaphores in a Web app is a bad idea. Any sort
of locking is bound to get you in trouble which is also why PHP resets
the semaphore at the end of a request.

Generally you will want to think beyond a single server and look at a
message passing mechanism to communicate between a PHP app and a
server process. I think my favourite way to implement this today is
through ZeroMQ. There is a good guide to it at:

http://zguide.zeromq.org/page:all
http://www.zeromq.org/bindings:php

Or if you want something higher level you could have a look at
Gearman. Your server could register itself as a Gearman worker and you
could use the nice Gearman API to communicate with the server.

-Rasmus

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



Re: [PHP] multi thread work?

2010-08-04 Thread Rasmus Lerdorf
On 8/4/10 10:27 AM, Alex Major wrote:
 -Original Message-
 From: Tontonq Tontonq [mailto:root...@gmail.com]
 Sent: 04 August 2010 18:21
 To: PHP General Mailing List
 Subject: [PHP] multi thread work?

 Hi
 how to make a script multi task  based like this

 ?


 for($i=1;$i=100;$i++)
 {


 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,
 'http://www.facebook.com/ajax/reqs.php?__a=1'
 );
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_USERAGENT, Opera/9.80 (Windows NT 5.1; U; tr)
 Presto/2.6.22 Version/10.50);
 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 curl_setopt($ch, CURLOPT_REFERER, http://www.facebook.com/reqs.php;);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
 curl_setopt($ch, CURLOPT_PROXY, 127.0.0.1:);
 curl_exec($ch);


 }
 ?


 lets say this takes 1000 seconds and it doesnt focus to another curl
 process
 before it finish the previous one

 is it possible to let the script focus another curl process without
 wait
 answer of the previous one

 i hope if u could understand me ^^
 
 This question has been asked several times over the last week, have a look
 over the archive ;).
 
 You need to be looking at something like process forking (
 http://php.net/manual/en/function.pcntl-fork.php ).

Definitely not.  You should be looking either at curl_multi or at
something like Gearman.  pcntl is very similar to eval for Web apps.  If
you find yourself using them, you know you have taken a wrong turn
somewhere.

-Rasmus

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



Re: [PHP] socket multithreading problem

2010-07-29 Thread Rasmus Lerdorf
On 7/27/10 7:04 AM, Ümit CAN wrote:
  I use PHP socket programming  and I wish  multithreading operation of
the socket .
 When I have many requests on this  socket , before the  first one request is 
 anwered , the second request  is not aswered  till the first one is finished.
 How can both  requests  work  together without  waiting each  other ? 

I assume you mean you have multiple sockets and not just one?  If it is
just one, you just need to write a little state machine that keeps track
of your requests since only one thing can happen at a time on a single
socket.

If you have multiple sockets you should be looking at
http://php.net/socket_select and not threads.  Threads and/or pcntl
processes would be a very inefficient way to deal with something as
simple as reading messages asynchronously from many sockets.

-Rasmus

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



Re: [PHP] the state of the PHP community

2010-07-29 Thread Rasmus Lerdorf
On 7/28/10 11:26 PM, Larry Garfield wrote:
 - Those driving PHP development itself (vis, writing the engine) don't seem 
 to 
 comprehend the idea of someone running a web site who isn't also a C 
 developer, sysadmin, and performance specialist.  If you don't have root 
 then 
 we don't care about you is the prevailing attitude I see.  I'm sure most of 
 PHP-DEV will disagree with that assessment but I've been reading the list for 
 3 years now and that sense is very clear.  That's quite unfortunate given 
 that 
 the vast majority of PHP scripts are still on shared hosting where you have 
 no 
 control over the environment at all.

The very basic reason for this is that we build stuff that we need.  We
will try to cater to others as well, but the things that receive the
most attention are the things that the people writing the code need
themselves for some reason.  None of us run an ISP with thousands of
virtual hosts on a single 32-bit machine and half a gig of ram.

It is just human nature.  PHP is not a product.  It is a shared tool and
the people capable of building the tool get a lot of say into what the
tool does and how it does it.  People who are not capable of building
the tool can shout suggestions from the sidelines and occasionally some
of these will stick, but often they won't.

-Rasmus

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



[PHP] Re: [PHP-INSTALL] Getting file pointer from file descriptor

2010-04-23 Thread Rasmus Lerdorf
You seem to be quite confused.  First of all, a function like fdopen() which
has never existed in any version of PHP, wouldn't read/write anything.  In C
that function will return a FILE pointer from a file descriptor.  You would
then use fread()/fwrite() to read and write from that FILE pointer.  But PHP
doesn't have file pointers nor file descriptors, so none of this applies to
PHP.  In PHP an open file is a resource just like an open database
connection is a resource.

So, is your question really how to read and write to files?  There are many
ways to do that.  The easiest is to just call
file_get_contents()/file_put_contents(), but you can also use
fopen()/fread()/fwrite() if you prefer that approach.

-Rasmus

On Fri, Apr 16, 2010 at 5:15 AM, Naga Kiran K k.nagaki...@gmail.com wrote:

 Hi Rasmus,

 Thanks for reply.
 The requirement I was looking for is to read/write given only the file
 descriptor number.

 PHP-CGI binary is invoked by a webserver that runs in jail-directory and
 doesn't have access to the file path directory.
 So, it communicates with another daemon that opens a socket to that file
 and in turn passes the file descriptor alone.

 Can you please suggest if there is any API in PHP that serves this
 requirement [read/write to given file descriptor]
 Please let me know if I need to provide more information.

 Thanks,
 Naga Kiran


 On Thu, Apr 15, 2010 at 7:33 PM, Rasmus Lerdorf ras...@lerdorf.comwrote:

 On 04/15/2010 06:52 AM, Naga Kiran K wrote:
  Hi,
 
  We are upgrading PHP from 5.2.3 to 5.3.2 and are facing few issues [like
  unsupported functions...]
 
  In PHP 5.2.3, fdopen was used to read/write to a file descriptor
  that's opened by another application.
 
  fdopen(fileDescriptorId,rw);  //It worked fine with PHP 5.2.3
 
  After PHP upgrade,its throwing undefined reference to 'fdopen'
 function.
 
  Please suggest whats the replacement for this in PHP 5.2.3 or any
  workaround.

 PHP has never had an fdopen() function.  It must be something in user
 space that provided that for you if you had it.

 -Rasmus




 --
 Regards,
 Naga Kiran



Re: [PHP] Best way to manage open slots for download

2006-12-31 Thread Rasmus Lerdorf
Aras wrote:
 First of all, Happy New Year for everyone in the list. I wish 2007 brings
 all us happiness, health and peace.
 
 I want to read your advises at a point i am stuck within, i have an
 application that serves downloads to clients. For some reason i am limiting
 total open slot for some group of users (not related to my technical
 question).
 
 Example;
 
 // CHECKS SLOT HERE
 
 else {  // IF THERE ANY AVAILABLE SLOTS SEND THE FILE
 
 // INCREMENT SLOT NUMBER BY 1
 
 $fp = fopen($pathside,r);
 
 if ($fp) {
 
   while (!feof($fp)) {
   echo fread($fp, 334);
 
   $bytes_out += 334;
   ob_flush();
 
   if ($bytes_out  $size) {
 
   // DECREASE SLOT NUMBER BY 1, BECAUSE THIS DOWNLOAD IS FINISHED
 
   }
 
   }
 
 }
 
 }
 
 
 Slots are recorded and checked from a simple mysql table. Everything works
 in this scenario. There is no problem if a person starts a download and
 finishes it, his slots get empty upon doing so. Yet if he cancelles the
 transfer, he will never reach my control structure to empty the slot. And
 slots will be full of zombies.
 
 I have thought of updating a mysql field for alive-connections in the while
 loop, but it will definitely add some load on my server. Updating a system
 file is not secure and good way.
 
 What other ways can you recommend to me for the situtation?

Read through this:

http://www.php.net/manual/en/features.connection-handling.php

-Rasmus

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



Re: [PHP] mime with php4.4.4 does not work anymore

2006-12-30 Thread Rasmus Lerdorf
Roger Thomas wrote:
 I have been serving my community with Invision Power Board (IPB) v1.3.1 
 Final. Things are working well with PHP 4.3.8 and Apache 1.3.29.
 
 Yesterday I just upgraded to PHP4.4.4 and I have problems with Excel and Word 
 attachments with IPB. Whenever I click on those attachments, I will get all 
 sorts of funny characters all over my browser screen. However, image 
 attachments are correctly displayed inline.
 
 I added --with-mime-magic=/usr/local/apache/conf/magic to configure but 
 nothing change. If I were to roll back to PHP 4.3.8, IPB works perfectly.
 
 What have I missed. Please advise. TIA.

I don't think anybody here can answer that without knowing how IPB
serves up those attachments.  Do they even go through PHP?  If not, then
it becomes a web server configuration issue.  If they do go through PHP,
what PHP functionality is IPB using?  Perhaps they are using the
deprecated mime_magic stuff?  They should be using pecl/fileinfo
functions if they need that stuff, but I think you will have to ask them.

-Rasmus

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



Re: [PHP] php 5 and register_globals=off gives lotsa errors

2006-12-30 Thread Rasmus Lerdorf
You did more than just turn register_globals off.  You also changed your
error warning level.  You have turned notices on.  Set the same error
warning level in your PHP 4 setup and you will see exactly the same
messages.

To be notice-free, your code should look like this:

 $action = isset($_GET['action']) ? $_GET['action'] : null;

replace null in the above with whatever you want your default action to
be there if it is not provided in the URL.

-Rasmus

Wikus Moller wrote:
 Hi to all.
 
 I am having huge problems running my script, which worked fine on a
 server with php 4 and register_globals turned on, on a server with php
 5 and register_globals turned off.
 
 I get errors around the area in my script where I use $_GET (not the
 only error). For example the following code on my index.php file which
 like many other sites I know, handles quite a large amount
 if(action==main); etc etc. :
 
 ?
 $action = $_GET[action]; //line 55
 $sid = $_GET[sid];   //line 56
 $page = $_GET[page]; //line 57
 $who = $_GET[who];   //line 58
 ?
 
 When I go to http://chillinglounge.net (where the error is located) I
 get the following error message(s):
 
 Notice: Undefined index: action in
 C:\websites\chillinglounge.net\public_html\index.php on line 55
 
 Notice: Undefined index: sid in
 C:\websites\chillinglounge.net\public_html\index.php on line 56
 
 Notice: Undefined index: page in
 C:\websites\chillinglounge.net\public_html\index.php on line 57
 
 Notice: Undefined index: who in
 C:\websites\chillinglounge.net\public_html\index.php on line 58
 
 Now if you would look at exactly the same script at
 http://ranterswap.net you'd see absolutely no errors.
 
 That's where I need your help. I know what is causing this error. I
 believe it's the fact that register_globals is turned off.
 
 But what I really want to know is: How do I fix it without trying to
 turn register_globals on via .htaccess (because it doesn't work)?
 
 Is there a function or some magic script that would to the trick?
 Or do I have to recode my entire script and how?
 

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



Re: [PHP] image commands (again)

2006-11-05 Thread Rasmus Lerdorf
Google Kreme wrote:
 On 05 Nov 2006, at 15:31 , Ron Piggott (PHP) wrote:
 Content-type: image/

 the browser expects only the image to output to the screen and no HTML
 
 As if should.
 
 Save the image in a temporary location and then send html that include
 and img ... / tag

You don't need to do that.  You can just call the PHP script directly
from the img tag.  Your only problem is how to pass the parameters.  You
obviously can't do a POST request from the img tag, so you either need
to pass the parameters as part of the url as in:

  img src=image.php?text=foosize=10 /

Or you use a cookie-based mechanism like a PHP session and refer to that
from the image.php script.

-Rasmus

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



Re: [PHP] ChangeLog PHP 5.2.0 - Fileupload

2006-11-04 Thread Rasmus Lerdorf
Christian Heinrich wrote:
 Hey all,
 
 I've just examined the latest Change-Log for Version 5.2.0 (see
 http://www.php.net/ChangeLog-5.php for details).
 
 Seems to be fine, but I couldn't figure out one point.
 
 The changelog talks about
 
 Added RFC1867 fileupload processing hook. (Stefan E.)
 
 and I actually don't know what is meant by that. I've looked up that RFC
 but it appears to me to be about multipart/form-data only. I confess
 that I haven't read it completly, but it didn't really seem to be
 talking about what I wanted to know.
 
 So, could anyone be so kind to explain me what is meant by that and what
 its used for?

Probably best explained with an example:

  http://progphp.com/upload.php

Try uploading a 200-300k file.

The source code is at:

  http://progphp.com/upload.phps

-Rasmus

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



Re: [PHP] Viruses

2006-11-02 Thread Rasmus Lerdorf
Beauford wrote:
 Does the PHP list not monitor spam or filter out viruses? I am getting a lot
 of this junk coming through the list. I am also getting some directly to
 this address, but obviously that is out of the lists control.

We filter 1000's of spam messages every day.  But a few do get through.
 Some spammer manually validate their addresses and then spam.  It's
very difficult to stop those.

-Rasmus

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



Re: [PHP] Microsoft Partners With Zend

2006-11-01 Thread Rasmus Lerdorf
Daevid Vincent wrote:
 -Original Message-
 From: Ed Lazor [mailto:[EMAIL PROTECTED] 
 Sent: Wednesday, November 01, 2006 12:05 PM
 Cc: Daevid Vincent; PHP General
 Subject: Re: [PHP] Microsoft Partners With Zend 

 ps...  I wonder if .NET will ever support PHP *GRIN*
 
 I guess that's sorta what I'm afraid of... PHP# 
 (like the did to Java - J++ - C# )
 
 Don't get me wrong. C# is a great language (probably one of the few things
 that M$ did right), and I'd LOVE to use a real IDE like Visual Studio to
 dev in... 
 
 But I'm also terrified they'll pervert PHP.

How?  Microsoft's only weapon here is to make PHP work better on
Windows.  They can't in any way make it worse on non-Windows platforms.
This is the sort of involvement we want from Microsoft.  We want them to
compete technologically as opposed to some of the crap we have seen from
them over the years.

And don't forget that press releases and partnerships mean very little
to an open source project.  They didn't partner with us, they partnered
with Zend.  That's not going to give them better access to commit code
to PHP.

The only slight negative as far as you are concerned could be that they
may divert some Zend resources to work on Windows issues that aren't
interesting to you.  But consider that there are 1133 people with PHP
cvs accounts.  Only 11 work for Zend, and out of those 11 only 3 have
committed anything substantial in the past year.  Zend resources are
already diverted to their various commercial projects.  And some of that
will most likely result in some contributions to PHP funneled through
one of the 3 active people, so that might be a bit low, but still.

The point is that PHP is a large open source project with broad support
from a number of companies and even more stubborn open source
developers.  No one company can pervert PHP.

-Rasmus

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



Re: [PHP] Microsoft Partners With Zend

2006-11-01 Thread Rasmus Lerdorf
Rasmus Lerdorf wrote:
 The only slight negative as far as you are concerned could be that they
 may divert some Zend resources to work on Windows issues that aren't
 interesting to you.  But consider that there are 1133 people with PHP
 cvs accounts.  Only 11 work for Zend, and out of those 11 only 3 have
 committed anything substantial in the past year.  Zend resources are
 already diverted to their various commercial projects.  And some of that
 will most likely result in some contributions to PHP funneled through
 one of the 3 active people, so that might be a bit low, but still.


Actually make that 5 active people in the past year.  I did an actual
cvs log check this time instead of just going from memory.  Not that
this was the point.

-Rasmus

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



Re: [PHP] PHP Memory Allocation (checked via TOP)

2006-10-31 Thread Rasmus Lerdorf
$str is 10 bytes
then you repeat it 200 times
That gives you 2000 bytes.  That's 20M not 10M

-Rasmus

Cabbar Duzayak wrote:
 Hi,
 
 I have written a simple test program to see how php allocates memory.
 Test code allocates ~10 Meg of RAM in an array within a loop till it
 runs out of memory as:
 
  $str = rand(65, 95) . rand(65, 95) . rand(65, 95) . rand(65, 95) .
 rand(65, 95);
  $aa[] = str_repeat($str, 200);
 
 What I don't understand here is, for every 10 Meg memory it allocates,
 mem usage goes up about 19 Megs when I look at this via top.
 Basically, it allocates from physical memory in the beginning, starts
 using swap when it is out of RES/Physical memory, which makes me
 assume that garbage collection should kick in for temporary string
 creations, and each new allocation increases the allocated memory size
 by 19 Megs.
 
 Any idea why this is happening, and why do you think memory allocation
 is so expensive in PHP?
 
 Thanks..
 
 
 Results of TOP:
 
  PID USER  PR  NI  VIRT  RES  SHR S %CPU %MEMTIME+  COMMAND
 21843 apache17   0 19292 5232 3832 S  0.0  0.5   0:00.04 php
 21843 apache16   0 38824  24m 3908 S  0.0  2.4   0:00.10 php
 21843 apache15   0 58356  43m 3912 S  0.0  4.3   0:00.17 php
 21843 apache16   0 77888  62m 3912 S  0.0  6.2   0:00.22 php
 21843 apache15   0 97420  81m 3912 S  0.0  8.1   0:00.29 php
 21843 apache15   0  114m 100m 3912 S  0.0  9.9   0:00.35 php
 
 
 Results of free -m:
 
 total   used   free sharedbuffers cached
 Mem:  1011138872  0  2 58
 Swap: 2008388   1619
 
 Mem:  1011158852  0  2 58
 Swap: 2008388   1619
 
 Mem:  1011177833  0  2 58
 Swap: 2008388   1619
 
 Mem:  1011196814  0  2 58
 Swap: 2008388   1619
 
 Mem:  1011216795  0  2 58
 Swap: 2008388   1619
 
 Mem:  1011234776  0  2 58
 Swap: 2008388   1619
 

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



Re: [PHP] How does the Zend engine behave?

2006-10-27 Thread Rasmus Lerdorf
Sean Pringle wrote:
 The Caching systems such as Zend Cache (not the Optimizer), MMCache,
 APC, etc are expressly designed to store the tokenized version of the
 PHP script to be executed.

 Note that their REAL performance savings is actually in loading from
 the hard drive into RAM, not actually the PHP tokenization.

 Skipping a hard drive seek and read is probably at least 95% of the
 savings, even in the longest real-world scripts.
 
 Interesting.  If PHP tokenization is such a small cost, what makes a
 special caching system better than the OS for caching files in memory
 after the first disk read?

APC actually executes the opcodes directly in shared memory, so unlike a
disk cache, you are not copying lots of stuff around.  APC does need to
copy some things down into process-local memory, but most can be left
where it is.  Disk caches also tend to expire pretty fast because
everything your OS does tends to touch the disk and when you application
starts eating memory your disk cache is the first to go when things get
tight.  With a dedicated shared memory segment that won't happen.
Things will stay put.

It is also possible to run APC in no-stat mode which means it will never
touch the disk at all.  If you are on an Intel cpu with an older OS like
freebsd4, disk-touching syscalls are massively slow and you can gain a
lot by skipping the up-to-date stat check on each request and include file.

Finally the compiler does more than just tokenize your script.  It will
cache functions and classes when it can and rewrite the opcodes so these
functions and classes won't have to be created at execution time.  Of
course, that assumes you haven't gone all framework-crazy and made
everything dynamic with autoload or weird conditional function and class
declarations.  If it becomes a runtime decision whether class or a
function is declared, or heaven forbid, the same class takes on
different signatures based on some runtime condition, then there isn't
much the compiler can do to speed that up.

-Rasmus

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



Re: [PHP] Non-blocking sockets

2006-10-27 Thread Rasmus Lerdorf
Jochem Maas wrote:
 Eric wrote:
 Stut wrote:
 Eric wrote:
 When I create a socket/stream that connects to a news sever and try
 to recv data from the socket when there is nothing there (Like if the
 server sends one line and I call recv twice) the socket freezes. I
 assume this is because using socket_create or fsockopen creates a
 blocking TCP/Stream socket by default. When I call
 socket_set_nonblock() and the socket_connect I get A non-blocking
 operation could not be completed immediately. Could someone show me
 exactly how to create a non-blocking TCP/Stream socket? Thanks in
 advance.
 I may be wrong but I think you need to set the socket non-blocking
 after the connect. You cannot do a non-blocking connect.

 -Stut
 Then the socket recv doesnt work. Gives me Unable read from socket.
 
 $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
 socket_connect($socket,news.csh.rit.edu,119);
 socket_set_nonblock($socket);
 socket_recv($socket,$buf,1024,0);
 echo $buf;
 
 I *think* you need to be looking here:
 
 http://php.net/manual/en/function.socket-select.php

I would actually suggest going a bit higher level and using
stream_socket_client() instead.  Using a stream is much more flexible.
See the manual page for the function for some examples.

-Rasmus

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



Re: [PHP] Parsing serialized PHP arrays in C

2006-10-21 Thread Rasmus Lerdorf

Kevin Wilcox wrote:

I have a feeling this may be the wrong group to ask this question, but
I thought that if it is, someone can point me in the right direction.

I'm working on a application written in C that needs to parse and
understand php arrays that have been serialized and stored in a MySQL
table. I started writing the parser and realized its not a trivial
task. I'm wondering if there is any source code in C to do what I'm
looking for? I googled many different combinations of keywords and
nothing useful came up. I even looked at the code in
ext/standard/var_unserializer.c, and I don't think what will port to a
stand alone application without extensive modifications.


Why not?  It is a rather simple re2c parser.  Don't look at 
var_unserializer.c, look at var_unserializer.re and read up on re2c.


  http://re2c.org/

You would obviously want to replace the creation of internal PHP data 
types with whatever you want to unserialize to in your app, but I don't 
see how you would find any code somewhere else where you wouldn't need 
to yank out the destination code from since that is going to be the 
unique part in each implementation.  And if you use the same re2c 
grammar that PHP uses, it will be correct.  Using any other 
implementation likely wouldn't be.


Of course, I also wouldn't suggest using serialized PHP for a target 
that wasn't PHP.  Why don't you look at json or perhaps wddx instead?


-Rasmus

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



Re: [PHP] LAMP benchmarking tool

2006-09-27 Thread Rasmus Lerdorf

Joseph Cheng wrote:

Is anyone using a reliable Linux/Apache/MySQL/PHP benchmarking suite?
There are benchmark software for individual pieces but I hope there is
one tool or several small tools that act together to give a picture of
how long a request takes from entering Apache, to PHP, to MySQL and
then back to the client.TIA!


There is no way a single tool can get you intra-request numbers for 
that.  Your best approach is to use a http benchmarking tool to measure 
your entire roundtrip (http://acme.com/software/http_load/) and then 
once you know your entire roundtrip time including latency numbers use a 
profiler (http://valgrind.org/info/tools.html#callgrind) to figure out 
where you are spending your time in your request.


-Rasmus

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



[PHP] Yahoo! HackDay

2006-09-22 Thread Rasmus Lerdorf
For any of you folks in the Bay Area, don't miss the open Hack Day at 
Yahoo next Friday/Saturday.  It is completely free and the density of 
web experts will be higher than at most conferences.


More info on it at the following links:

http://yuiblog.com/blog/2006/09/22/yahoo-devday-schedule/
http://nate.koechley.com/blog/2006/09/22/hookytime-yahoo-developer-day-hack-day-on-sept-29th-and-30th/
http://del.icio.us/chadd/yhackday

-Rasmus

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



Re: [PHP] Re: Where to download APC for windows?

2006-08-23 Thread Rasmus Lerdorf
It's a pecl extension, so it is with all the other pecl extensions for 
Windows at http://pecl4win.php.net/


-Rasmus

steve wrote:

Yeah, sorry, it is missing from a test version of PHP 5.2. In the test
version, it is not available, nor is it on snaps. Likely doesn't work.

On 8/23/06, Alex Turner [EMAIL PROTECTED] wrote:

At the risk of being flamed to death, I thought it was in ext in the
standard windows distro.  If it is not, I am stuffed if I can remember
where I got it from (blush).

AJ

steve wrote:
 I used to have a bookmark on where to download APC for windows. Anyone
 have a link?

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






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



Re: [PHP] auto_globals_jit breaks $_SERVER var

2006-08-14 Thread Rasmus Lerdorf

Artzi, Yoav (Yoav) wrote:

I have the following in my php.ini:
register_globals = Off
register_long_arrays = Off
register_argc_argv = Off
auto_globals_jit = On
 
The following PHP code prints nothing:

?php
$webroot = $_SERVER['DOCUMENT_ROOT'];
$server = $_SERVER[HOST];
$file = $_SERVER[SCRIPT_FILENAME];
$transport = $_SERVER[REQUEST_TRANSPORT];
$port = $_SERVER[SERVER_PORT];
print $webroot;
print $server;
print $transport;
?
 
The rest of the php.ini is like php.ini-recommended that comes with the

source. Any idea what might be the problem?


Do you have APC enabled?  If so, upgrade to a more recent version. 
Preferably the CVS one.


-Rasmus

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



Re: [PHP] Re: Internet Explorer doesn't display UTF-8 page using UTF-8 encoding

2006-08-13 Thread Rasmus Lerdorf

tedd wrote:

At 6:48 PM -0700 8/12/06, Rasmus Lerdorf wrote:
By the way, everyone should be setting a charset.  If you don't set 
it, IE will look at the first 4k of the body of the page and take a 
wild guess.


-Rasmus


-Rasmus:

Ok, but why doesn't w3c use it?

http://validator.w3.org   (check source)

I'm not sure what to do re charset. I've been told by credible sources 
to always use it and never use it -- which is correct? Or, is this 
one of those it depends things?


W3C is all about standards.  IE is all about not following standards. 
If you want your site to work in the real world you should always set a 
charset.  If you set it in your response header there is no need to set 
it in each page, and if you look closely, you will see that this is what 
 w3.org is doing:


9:55am shiny:~ telnet validator.w3.org 80
Trying 133.27.228.132...
Connected to validator.w3.org.
Escape character is '^]'.
HEAD / HTTP/1.0

HTTP/1.1 200 OK
Date: Sun, 13 Aug 2006 18:42:15 GMT
Server: Apache/2.0.54 (Debian GNU/Linux) mod_perl/1.999.21 Perl/v5.8.4
Accept-Ranges: bytes
Connection: close
Content-Type: text/html; charset=utf-8

-Rasmus

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



Re: [PHP] Re: Internet Explorer doesn't display UTF-8 page using UTF-8 encoding

2006-08-12 Thread Rasmus Lerdorf
IE doesn't actually support XHTML, so if your primary target for 
something is IE, you really shouldn't be using XHTML.  Even IE7 doesn't 
fully support it.


Setting the charset in the response header like you did is the best 
approach.  You can do it for all your pages in your php.ini file with:


default_charset = UTF-8

If you want to do it in your page contents, it needs to look like this:

META HTTP-EQUIV=CONTENT-TYPE CONTENT=text/html; charset=UTF-8

Your attempt with the xml header would have worked if IE knew what the 
heck XHTML was.


By the way, everyone should be setting a charset.  If you don't set it, 
IE will look at the first 4k of the body of the page and take a wild 
guess.  If it guesses wrong, typically because someone injected UTF-7 
into your page, then you have an XSS on your hands.


-Rasmus

Jonny Bergström wrote:
It's me again. I might have solved it... in a way. Still quite puzzled 
about

why IE don't give a dime about the meta encoding line in the html head tag.

Here's what I did. The aforementioned header file now adds a header()
statement sending a content-type that also tells the charset, utf-8. :

---snip---
?php
header('Content-Type: text/html; charset=utf-8');
echo '?xml version=1.0 encoding=UTF-8?';?
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN 
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
html
   head
   meta name=Content-type content=text/html; charset=UTF-8 /

---snip---


I don't know if it's the best way to solve it but IE seems happy with it,
and I haven't seen any sideeffects in FF so far.



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



Re: [PHP] Parsing RSS

2006-08-12 Thread Rasmus Lerdorf

John Taylor-Johnston wrote:
Is there something already created to open an rss file, parse it, and 
include() the useful stuff into an html file?

Not all my students have an rss reader.

http://jtjohnston.ca/jtjohnston.rss


RSS is just XML.  Use SimpleXML to map it to a PHP object and just print 
out whatever you want from it directly.


eg.

?php
$rss = simplexml_load_file('http://jtjohnston.ca/jtjohnston.rss');
$channel = $rss-channel;
echo EOB
img src={$channel-image-url} style=float: right;/
h1{$channel-title}/h1
h2{$channel-description}/h2
EOB;
foreach($channel-item as $item) {
  echo EOB
h3a href={$item-link}{$item-title}/a ({$item-pubDate})/h3
{$item-description}
br clear=left /
hr /
EOB;
}
?

Very ugly HTML markup there, of course, but add a bit of CSS and make it 
prettier.


-Rasmus

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



Re: [PHP] Multiple Includes vs. One Long Include (Functions)

2006-08-10 Thread Rasmus Lerdorf

Kevin Murphy wrote:
I was just wondering if there was any thought one way or another on the 
best practice for doing this.


Lets say I have 10 functions that I want to reuse on my site. Not every 
page needs every function. So I move the function to an external page 
and then require it for the page.


The question is, is it better to have all 10 of those functions in a 
single file that is called once from each PHP page, even though some 
will not be used, or is it better to put one function per include and 
then on each PHP page call just the functions that I need for that page?


require (all10.php); // one long page, but only called once.

vs.

require (function1.php);// multiple short pages with multiple calls.
require (function2.php);
require (function4.php);
require (function6.php);
require (function8.php);


Without an opcode cache, a single large include file will always beat 
multiple include files.  Even if it is large, a couple of extra block 
reads is still going to be way faster than finding and opening a bunch 
of small ones.


With an opcode cache the difference is minimized.  And if you turn off 
file stats (apc.stat=0 in APC) then I doubt you could measure a 
difference.  The executor would be executing the opcodes directly out of 
shared memory and whether that shared memory is arranged as multiple 
entries or a single entry with many functions doesn't really matter when 
it comes to performance.  With file stats on, a single file would again 
be quicker because you would only need a single stat instead of multiple 
stats.


-Rasmus

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



Re: [PHP] Stop process when user close window browser

2006-06-30 Thread Rasmus Lerdorf

weetat wrote:

Hi Thomas,

  Yes. I read the manual regarding the connection handling.
  However ,in my php program , the execution did not stop , because i 
have logger which log sql statement INSERT statement when inserted 
data to database is ok .


When i close the browser , the sql execution still running, statement is 
logged.


Any idea how to stop it ? Because it cause my web page to be slow.


PHP doesn't know the browser has gone away until it tries to write 
something to it.  So if you are inside a long-running SQL-query and the 
browser drops, nothing will happen until the query call returns and you 
try to write something.


-Rasmus

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



Re: [PHP] When is z != z ?

2006-06-06 Thread Rasmus Lerdorf

Martin Alterisio wrote:

You're right about ++ operator not to be considered a math operator, my
mistake. What I should have said is that the usual connotation and expected
behaviour of ++ and the comparison operators is to give iteration
capabilities to a certain data type, as used in a for statement. For 
that to

happen certain constrains must be true for these operators, one of them
being: any  ++any, which is not true for the way these operators behave in
php.

I'm not saying It's wrong let's change it right away!, I completely agree
that these rules can be bent on a not strongly typed language. The point 
I'm
trying to make, the thing I want to understant without a trace of doubt, 
is:

is it really worthy the functionality supplied with the string ++ operator
as it is? I don't see its usefullness yet.


It has been in PHP from the very beginning.  So 10+ years.  In that time 
it has been sparingly used, granted, but at the same time it really 
hasn't gotten in the way and removing it would break a number of legacy 
applications.


There were a lot more operators that worked on strings in the early 
days.  '*' would do a cross-product, for example, treating the two 
string operands as vectors and returning a vector orthogonal to both of 
these.  But I got tired of trying to explain to people what a cross 
product was and how strings mapped to vectors in Euclidean space and 
removed that.  You could also at one point do abc-b to get ac.


-Rasmus

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



Re: [PHP] Controlling DomDocument's load and loadHTMLFile Request

2006-06-06 Thread Rasmus Lerdorf

Shu Chow wrote:
Is there any way to alter the header of DomDocument's load/loadHTMLFile 
request?  I have a file that will display certain content for certain 
user agents.  I'd like to be able to spoof the UA of the request.


Ah, a good question the answer to which demonstrates the magic of PHP 
5's stream contexts which is meant to solve this exact problem.


The example in the documentation is even exactly the user-agent one.  See:

  http://php.net/libxml_set_streams_context

-Rasmus

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



Re: [PHP] When is z != z ?

2006-06-06 Thread Rasmus Lerdorf

Richard Lynch wrote:

On Mon, June 5, 2006 9:00 pm, tedd wrote:

Does that make more sense?

Maybe to you, but not me.


   a
   b
   c
   .
   .
   .
   x
   y
   z
  aa
  ab
  ac
   .
   .
   .
  ax
  ay
  az
  ba
  bb
  bc
   .
   .
   .
 aaa
   .
   .
   .
 zzz

   .
   .
   .

   .
   .
   .

   .
   .
   .


It's just like 1 thru 9 followed by 10, except that it is NOT an
ordered set in terms of  and 


In my last post I showed an actual sequence which is debatable. It
could be interpreted that the infinite set starts at a, aa, aaa,... 
and never reaches b. Oddly enough, this could be viewed in all sorts
of ways. It's probably best if we don't look at characters as numbers.


EXACTLY!

They aren't numbers.

So doing ++ to one of them, doesn't necessarily end up with an ordered
set.

Rasmus chose to make ++ be useful for generating sensible sequential
file names, not sensible ordered strings.


Well, it does other sequences too and the first priority is always to 
try to convert to a number.  For example, try incrementing the following 
strings: 1, 1.5, 0xf8, 10e2
These all end up being converted to numbers (integers or floats as 
appropriate) and hopefully they end up with the value everyone would 
expect.  Since the Web by definition is untyped, all we get passed 
around between the browser and the server are strings, so we need to 
make 123 passed as a string behave as the number 123 as much as we 
can.  Otherwise we would spend a lot of time type juggling.  Having 
123++ not end up being 124 but instead do something to increment the 
ascii values behind the string instead would create chaos.


So, given that in any instance where we can convert the string to a 
number ++ logically increments that number by 1 spot in the numeric 
sequence.  It follows that anywhere we can determine a logical sequence 
for the string, ++ should increment that sequence.  The other option 
would be that anything that can't be converted to a number would end up 
being 0, and whatever++ would always be 1.


Or we try to do something a bit more creative which always runs the risk 
of surprising people.  In this case a2++ becomes a3 and c9++ 
becomes d0.  If we have a character that doesn't infer any sort of 
logical sequence, like  then the ++ does nothing.  So ++ stays at 
.  However 3 becomes 4 and b++ becomes c.  99z++ 
becomes 100a and 1z9z9z++ becomes 2a0a0a and yes, of course z++ 
becomes aa which is what caused this entire thread.


-Rasmus

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



Re: [PHP] When is z != z ?

2006-06-05 Thread Rasmus Lerdorf

tedd wrote:

For example, the Unicode issue was raised during this discussion -- if php 
doesn't consider the numeric relationship of characters, then I see a big 
problem waiting in the wings. Because if we're having these types of 
discussions with just considering 00-7F characters, then I can only guess at 
what's going to happen when we start considering 00-FF code-points.

Now, was that enough said?  :-)


I don't think you really understand this.   and  are collation 
operators when they operate on strings.  They have absolutely nothing to 
do with the numeric values of the characters.  It just so happens that 
in English iso-8859-1 there is a 1:1 relationship between the numeric 
values and the collation order, but you can think of that as dumb luck.


To better understand this, I suggest you start reading here:

  http://icu.sourceforge.net/userguide/Collate_Intro.html

Note one of the points on that page.  That in Lithuanian 'y' falls 
between 'i' and 'k'.  So even without going into Unicode and just using 
low-ascii, you have these issues.


Now, until we get to PHP 6, we don't have decent Unicode support and we 
don't have LOCALE-aware operators.  You will have to manually use 
strcoll() to get them, but that is going to change and you will have the 
ICU collation algorithms available and for Unicode strings it will be 
automatic.  You can still have binary-strings if you don't want 
locale-aware collation, of course.


-Rasmus

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



Re: [PHP] When is z != z ?

2006-06-04 Thread Rasmus Lerdorf

tedd wrote:

Hi gang:

Here's your opportunity to pound me again for not knowing the basics of php.

I vaguely remember something like this being discussed a while back, but can't 
find the reference.

In any event, if one uses --

for ($i=a; $iz; $i++)
  {
  echo($i);
   }

-- it stops at y

But, if you use --

for ($i=a; $i=z; $i++)
  {
  echo($i);
   }

-- it prints considerably more characters after z than what one would 
normally expect -- why is that?

Just stopping at z would seem to make more sense, wouldn't it? After all, when $i = z 
in the first expression, then wouldn't $i be equal to z in the second expression and thus halt 
the operation?

What am I missing here?


It's a bit of a quirk.  z++ is aa and aa  z.  I would guess 
this would loop until until just before za which would be yz.


It's a bit like looping through the hexadecimal characters.  You would 
have the same effect.  However instead of being base-16 with 0-9-a-f you 
have base-26 using a-z.


-Rasmus

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



Re: [PHP] When is z != z ?

2006-06-04 Thread Rasmus Lerdorf

Martin Alterisio wrote:

2006/6/4, Rasmus Lerdorf [EMAIL PROTECTED]:


tedd wrote:
 Hi gang:

 Here's your opportunity to pound me again for not knowing the basics of
php.

 I vaguely remember something like this being discussed a while back, 
but

can't find the reference.

 In any event, if one uses --

 for ($i=a; $iz; $i++)
   {
   echo($i);
}

 -- it stops at y

 But, if you use --

 for ($i=a; $i=z; $i++)
   {
   echo($i);
}

 -- it prints considerably more characters after z than what one would
normally expect -- why is that?

 Just stopping at z would seem to make more sense, wouldn't it? After
all, when $i = z in the first expression, then wouldn't $i be equal 
to z

in the second expression and thus halt the operation?

 What am I missing here?

It's a bit of a quirk.  z++ is aa and aa  z.  I would guess
this would loop until until just before za which would be yz.



What?
z++  z returns true? =S
Is there a reason for this? Why aren't they handled like C chars?


Because PHP is not C.  If you want them handled by their char codes, 
then do so with chr() calls.



It's a bit like looping through the hexadecimal characters.  You would

have the same effect.  However instead of being base-16 with 0-9-a-f you
have base-26 using a-z.



0xF++  would be 0x10 which is greater than 0xF (0xF  0x10). It's not the
same.


Sure it is.  If you treat 0x10 as a string the same way he is treating 
these as strings, then 0x10 is going to be smaller than 0xF.


The fact is that there is just no right answer for what z++ should do.

-Rasmus

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



Re: [PHP] When is z != z ?

2006-06-04 Thread Rasmus Lerdorf

tedd wrote:

But, what brothers me about the routine, is that is DOES print z where it is supposed 
to. In other words, the characters a-z are output before continuing with aa and so on. The 
operation doesn't end with z.


Your condition for the loop to continue is $i=z.

When $i = y it will obviously continue because y  z
When $i = z it will obviously continue because z = z
When $i = aa it will obviously continue because aa  z

It doesn't stop until you get to z+something.  As in za because at 
that point za  z so the last thing you see is the one before za 
which would be yz.



Here's another way to look at it. All characters before z are less than z -- correct? So, what 
value are all characters after z (i.e., aa-yz)? They cannot be greater than, nor can they be 
less than. So, what are they?


But you are not comparing things in the same context here.  Strings are 
naturally compared alphabetically while you are thinking they are 
compared numerically somehow.  Think of sorting a set of words.  Would 
you expect aa to sort before or after z ?


So yes, like I said, it is a bit of a quirk, but there is no good answer 
to what z++ should be and we certainly don't want to change the 
default comparison mechanism to not compare strings alphabetically 
because that would screw up all sorts of stuff including usorts and 
peoples' expectations.  It's just in this case where you have gotten it 
into your head that incrementing strings is a good thing to do.


You'd be much better off with a range call to quickly generate a range 
of characters.  You could then loop through that character by character. 
 Or use the chr() function to work with character codes instead.


-Rasmus

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



Re: [PHP] When is z != z ?

2006-06-04 Thread Rasmus Lerdorf

Martin Alterisio wrote:


Still:
anything  ++anything
should be true, or at least that's what they taught me on abstract data
types design, and I think they're right (at least this time)


In loosely typed languages that is not always true.  Operators have to 
guess at the type and try to do what the user expects.  There will 
always be edge cases.  Being able to increment strings is pretty handy 
when you need to create sequences for unique file and directory names.


For example, this also works:

$filename = file1;
$filename++;
echo $filename;

You would get file2 from this.  Think about the amount of code you 
would need to write in C to make that work?


Then change $filename to fileA and increment it.  And you get fileB. 
 When we get to fileZ we don't want to go off into unprintable 
character land, we want to try to stick with the pattern.


-Rasmus

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



Re: [PHP] When is z != z ?

2006-06-04 Thread Rasmus Lerdorf

Martin Alterisio wrote:
I still don't see why this functionality should be a native operator of 
the language.
It doesn't seem natural that ++ operator understands that the string 
could be an enumeration of some kind. I believe that such things should 
be left to the coder who knows what the string is really representing, 
not to the language.


That's the strictly typed argument.  If you always force people to 
declare their types and you never automatically convert them, then you 
have a strictly typed language.  You have the same thing happening for 
something like:


 echo 2+3;

In a strictly typed language that would spew an error.  In a loosely 
typed language like PHP you get 5


And yes, I agree that ++ on strings is getting near the edge of that, 
but there has to be an edge somewhere and not everyone is going to agree 
on exactly where to draw the line.


-Rasmus

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



Re: [PHP] When is z != z ?

2006-06-04 Thread Rasmus Lerdorf

tedd wrote:

At 12:27 PM -0700 6/4/06, Rasmus Lerdorf wrote:

tedd wrote:

But, what brothers me about the routine, is that is DOES print z where it is supposed 
to. In other words, the characters a-z are output before continuing with aa and so on. The 
operation doesn't end with z.

Your condition for the loop to continue is $i=z.

[1] When $i = y it will obviously continue because y  z
[2] When $i = z it will obviously continue because z = z
[3] When $i = aa it will obviously continue because aa  z


I agree with [1] and [2], but [3] is where we part company. You see, if you are right, then 
aaa would also be less than z, but that doesn't appear so.


Of course it is.

php -r 'echo aaa  z;'
1


Not meaning to infer that you don't know this, because I know you do -- so I 
must be confused.

Yes, it is my contention that strings are numerical -- you don't store A in 
memory, you store 0100 001, or ASCII DEC 65.

Likewise a is DEC 97 (0110 0001) and z is DEC 122 (0111 1010) and if I compare a to 
z , it will always be less by numeric definition.

However, if I compare aa with z, then what? Is the numerical translation of 
the strings --

0110 0001 0110 0001  0111 1010

equal to TRUE -- I don't think so.


No, but we are talking about collation here, not representation.

Likewise, is the string aaa greater than z -- yep, I can buy that. 


Well, it isn't.  So the bulk of your rant is rather meaningless.

-Rasmus

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



Re: [PHP] When is z != z ?

2006-06-04 Thread Rasmus Lerdorf

tedd wrote:

At 1:09 PM -0700 6/4/06, Rasmus Lerdorf wrote:

I agree with [1] and [2], but [3] is where we part company. You see, if you are right, then 
aaa would also be less than z, but that doesn't appear so.

Of course it is.

php -r 'echo aaa  z;'
1


You missed the point, why does --

for ($i=a; $i=z; $i++)
  {
  echo($i);
   }

-- not continue past aaa? Clearly, if aaa is less than z then why does the loop 
stop at yz?


I thought I explained that a few times.  The sequence is:

a b c ... x y z aa ab ac ... yx yy yz za zb zc ... zy zx zz aaa aab

Your loop stops at yz and doesn't get anywhere near aaa because za  z

-Rasmus

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



Re: [PHP] When is z != z ?

2006-06-04 Thread Rasmus Lerdorf

Larry Garfield wrote:

On Sunday 04 June 2006 15:04, tedd wrote:


Yes, it is my contention that strings are numerical -- you don't store A
in memory, you store 0100 001, or ASCII DEC 65.


In a low-level language like C, that matters.  One doesn't have strings, one 
has numbers that happen to map to a symbol.


In PHP and other high-level languages, strings are their own datatype.  They 
may or may not even be stored as standard ascii number codes in order 
internally.  You have to think of them as strings, not as numbers.  There are 
no numbers involved here.  There are only strings.  


Likewise a is DEC 97 (0110 0001) and z is DEC 122 (0111 1010) and if I
compare a to z , it will always be less by numeric definition.


In C or C++, yes.  In PHP, do not assume the same string-number mapping.  
Numeric definition is irrelevant.


Right, and now bring Unicode into the picture and this becomes even more 
true.


-Rasmus

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



Re: [PHP] Garbage collection and strange session behaviour

2006-06-04 Thread Rasmus Lerdorf
Are you actually hitting this race condition in the real world?  With a 
decently long maxlifetime setting I can't really see this being a 
realistic problem.  Remember the timer is reset on every access.


-Rasmus

BNR - IT Department wrote:

Hi,
Here is a simple script:

? // BEGIN OF A SCRIPT
/* #1 */ ini_set('session.gc_maxlifetime', '3');
/* #2 */ ini_set('session.gc_probability',1);
/* #3 */ ini_set('session.gc_divisor',1);
/* #4 */ sleep(5);
/* #5 */ session_start();

$sessvar = empty;
if (!isset($_SESSION['a_sess_string'])) { /* #6 */
/* #7 */ $_SESSION['a_sess_string']= abcd;
/* #8 */ echo This is a newly created session, so we put a fresh
variable in it!;
} else {
$sessvar = $_SESSION['a_sess_string'];
/* #9 */ print(We have sessvar = '.$sessvar.' here, so - Is the
session OK??? Maybe, but the session file '/tmp/sess_?' has been
deleted!);
}
/* #10 */ print(br.session_id(). -that's our session id, hmmm);
? // END OF A SCRIPT

The lines from #1 to #3 intentionally set these parameters to the garbage 
collector just to speed up the results of the problem.

#4 - we're sleeping 

So, after first run we have: after #5 - a new session, #7 puts a variable 
in the session and #8 tells us about that.

After #5 we also have the session file /tmp/sess_? written out
there anywhere.

On second run after #5 (we've been sleeping enough on #4 to have our
session announced old, ...dead-man-walking... - quotation from 'The
Green Mile' movie), the gc-monster is awaken and hungry for eating old
session files. Finally we have the session file /tmp/sess_? deleted 
by the garbage collector after #5.

That's guaranteed by #1 - #4.

[If we put another 'sleep' after /* #5 */session_start(),
we may have time to switch to '/tmp' directory and persuade ourselves
that there is no session file any more after the execution of #5.]

No session file - no session variables anymore, no session at all???
WRONG ANSWER!
We are sent to the 'else' clause, so $_SESSION['a_sess_string] is set
and alive , and its value - additionally - is the one before the session
file has gone (deleted) - abcd in my example.

Obviously 'session_start()' first fills all of the sesion variables into
memory, and after that shoots the garbage collector to go to finish its
cleaning work. The session file is deleted, but inside the session, in
our script, we are not acquainted with that... Until the end of script we 
are happy that everything is all right, but probably this self-confidence 
could lead us to some troubles later.


Is there a workaround? Without going to the file system to check if the
file still exists? A smart and elegant PHP session way, without any
if-file-exists-checking functions?

P.S. (To the administrators/moderators/whatever of this mailing list) - Please 
tell the people - write it somewhere on http://www.php.net/mailing-lists.php - 
that there is no chance to get subscribed if they are using any public mail 
address like @yahoo.com. It took me 2 days, I struggled like a pig with a 
pumpkin to find out...

-
Bulgarian National Radio
IT Department
(+359 2) 9336 615
BNR - Sofia, Bulgaria



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



Re: [PHP] OO purism sucks - this is a rant for anyone who is allergic to that kind of thing...

2006-06-02 Thread Rasmus Lerdorf

Jochem Maas wrote:

I understand the point you made below - you have made this argument before
and I, for one, accepted it as valid when I first read the discussion
on internals - which is why I avoided ranting about that (and changes 
like it)


But you didn't avoid it, you used it as an example to back up your rant.

And on the OO side your argument gets shaky as well.  The whole point of 
OO is to add a very structured layer on top of your code to make it more 
consistent and more maintainable than the equivalent procedural code. 
There is nothing you can do in OO that you can't do with completely 
freeform procedural code.  When you choose to go OO, you choose a set of 
rules and a certain code structure that by definition is going to be 
somewhat constrained.  The argument over exactly how constrained this 
should be and where we should loosen things up will continue until the 
end of time.  PPP and Interfaces are all about constraints.  They serve 
no practical purpose whatsoever other than to add constraints.


And saying that these OO issues is slowing down PHP 5 uptake is a bit of 
a red herring.  We are competing against ourselves.  PHP 4 works 
extremely well.  There is a lot of code written for it and it works.  I 
seriously doubt very many people are not upgrading to PHP 5 because of 
some debatable edge-case OO thing.  People are not upgrading to PHP 5 
because PHP 4 works just fine for them and they haven't yet discovered 
things like SimpleXML and some of the other killer features of PHP 5.


-Rasmus

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



Re: [PHP] OO purism sucks - sell me on PHP5?

2006-06-02 Thread Rasmus Lerdorf

[EMAIL PROTECTED] wrote:


If it ain't broke, don't fix it works for a while, but if there are easier 
and/or better ways to do things in PHP5, I want in!  So someone sell me on this from the 
point of view of someone who's upgraded and has learned the joys of PHP5.  So far what 
I've found online has been little more than a list of new features without an idea of how 
much of a headache they're going to save me in the future.


To me the main user-visible benefits of going to PHP 5 are (ignoring the 
OO changes for now):


1. Simplexml

eg. One-line RSS parser (of Flickr's upload queue feed)

  $url = 'http://www.flickr.com/services/feeds/photos_public.gne';
  foreach(simplexml_load_file($url)-entry as $it) echo $it-content;


2. Much improved DOM support

eg. various things you can do to a DOM

  // First, load your XML document into a DOM
  $dom = domdocument::load('test.xml');

  // Apply a stylesheet to the dom
  $proc = new xsltProcessor;
  $proc-importStyleSheet($domxsl);
  echo $proc-transformToXML($dom);

  // xpath query on the dom
  $ctx = new domXPath($dom);
  $result = $ctx-query('/top/[EMAIL PROTECTED]  3]/foo/text()');
  foreach($result as $node) {
echo $node-nodeValue;
  }

  // pull it into simplexml and access it
  $s = simplexml_import_dom($dom);
  echo $s-child[0]-foo;


3. xmlreader/xmlwriter

eg. SAX document validation using xmlreader

  $reader = new XMLReader();
  $reader-open('test.xml');
  $reader-setParserProperty(XMLReader::VALIDATE, true);
  while($reader-read());
  echo $reader-isValid();


4. PDO

eg. Prepare execute against MySQL with named parameters

  $pdo = new PDO('mysql:dbname=testdb');

  $sql = 'SELECT name, colour, calories
  FROM fruit
  WHERE calories  :calories AND colour = :colour';
  $prep = $pdo-prepare($sql);
  $prep-execute(array(':calories' = 150, ':colour' = 'red'));
  $red = $prep-fetchAll();


5. SOAP

eg. Exposing your PHP code as a SOAP web service

  function Add($x,$y) {
return $x+$y;
  }
  $server = new SoapServer(null,array('uri'=http://test-uri/;));
  $server-addFunction(Add);
  $server-handle();


6. SPL

eg. Iterating over entries in a directory

  $dir = new DirectoryIterator('.');
  foreach($dir as $ent) echo $ent;


7. Filter

eg. Define a default filter and use form input safely without cluttering
up your code with htmlspecialchars() calls everywhere and provide
easily auditable access to the unfiltered data

  php.ini: filter.default = special_chars

  echo $_POST['data'];
  $raw = input_get(INPUT_POST,'data', FILTER_UNSAFE_RAW);


8. Native Date/Time mechanism

Date/time functions now behave exactly the same way on every platform 
regardless of the differences in locales if you choose to use the native 
mechanism.


Beyond that the compiler produces smaller opcode arrays and the executor 
is faster.  Not a directly visible thing, and this is still improving, 
but definitely a plus.


Note that for all of this I am referring to PHP 5.1.x, not 5.0.x.

-Rasmus

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



Re: [PHP] OO purism sucks - sell me on PHP5?

2006-06-02 Thread Rasmus Lerdorf

tedd wrote:

At 9:00 AM -0700 6/2/06, Rasmus Lerdorf wrote:

[EMAIL PROTECTED] wrote:



-snip- (a bunch of things over my head)


I thought I kept the examples pretty simple actually.  If you have 
specific questions on them I would be happy to explain them in more detail.


-Rasmus

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



Re: [PHP] OO purism sucks - this is a rant for anyone who is allergic to that kind of thing...

2006-06-01 Thread Rasmus Lerdorf

Robert Cummings wrote:


Well there was a segfault, but that's fixed now, now the warning is
thrown because of some purist attitude that says it's incorrect to pass
a literal to a reference expecting parameter... I can see how that's an
issue in C with pointers, or in a strongly type language like Java, but
part of PHP's popularity is that while it shares a lot of functions with
C, it is neither C nor Java, but rather a much simpler system that
generally for all the novices out there works well.


Stuff like this is a bug in your code.  It has nothing to do with purism:

function inc_arg($arg) {
  $arg++;
}
inc_arg(3);

You have specifically defined your function to modify the argument yet 
you pass it something that has no storage and thus there is no way to 
use that modification.  For the most part I agree that we need to keep 
the language as flexible and forgiving as possible, but where we are 
able to detect code that obviously doesn't do what the programmer 
intended, it is tremendously helpful to get a descriptive error.


As far as functions returning references, you are right that returning a 
literal there sometimes makes sense, but this can also hide a bug which 
is why this only throws a notice.


You could argue that we could try to look ahead and see what is actually 
done with the passed argument to see if it is modified, or that we could 
try to figure out whether the returned reference is actually used as 
such, but that is technically extremely difficult given the way things 
work internally.  So given the choice between ignoring extremely 
suspicious code like this and throwing an error/warning, I'd rather be 
told about it and in the edge cases where I really do want the 
equivalent of a NOP in my code, it isn't that hard to force it by adding 
a dummy storage variable along with a comment explaining why you need to 
do that.


-Rasmus

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



Re: [PHP] triming a query

2006-05-14 Thread Rasmus Lerdorf

Ross wrote:
Not so good with the string functions but I want to remove the last 15 
characters from a query. Thought this would work.


echo the query is.rtrim($query, 15);


echo the query is.substr($query,0,-15);

-Rasmus

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



[PHP] Re: Status report on mailing list?

2006-05-09 Thread Rasmus Lerdorf

John Hicks wrote:

Spam has suddenly swamped the PHP mailing lists.

(Some of you may have better filters than I and not noticed it.)

Apparently the list had been moved to a new server and it hasn't been 
configured properly yet.


I fear many will unsubscribe and the list will lose much of its utility 
if it's not fixed soon.


Does anyone have any info on what happened and when it will be fixed?


The lists have not been moved to a new server.  The spam filtering 
mechanism just had an issue yesterday and was fixed a couple of hours ago.


-Rasmus

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



Re: [PHP] Dates before 1970

2006-04-13 Thread Rasmus Lerdorf

Suhas wrote:

Hello,

I have a project that deals with the date time stamps since 1900 (and
past), any suggestions about a good class that handles Date Time
Format before 1970. I really like date() function and want something
similar.


date() uses Unix timestamps which on most Unix platforms goes from 
-MAX_INT to MAX_INT which means the date range is actually
12:45:52 12/13/1901 to 07:14:07 01/18/2038.  So you might be able to get 
away with it.


You can check it with:

echo date(h:i:s m/d/Y,-2147483648);
echo date(h:i:s m/d/Y, 2147483647);

Windows, not being Unix, doesn't understand that the timestamp can be 
negative, although I think someone fixed that in PHP 5.  In my 11+ years 
of PHP I have yet to run PHP on Windows, so I wouldn't know.


-Rasmus

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



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-11 Thread Rasmus Lerdorf

tedd wrote:

Here is an example Wez wrote years ago:


-snip code -

Years ago?

stream_socket_client() is php5.

How long ago did php5 launch?


The first beta was in June 2003.  But the streams code was written well 
before that.


-Rasmus

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



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-11 Thread Rasmus Lerdorf

Richard Lynch wrote:

On Mon, April 10, 2006 10:24 pm, Rasmus Lerdorf wrote:

You could volunteer to help maintain the user notes.


I've just spent five/ten minutes with Google and php.net trying to
find the best way to volunteer to do just that...

Admittedly not a LOT of effort, but...

Where do I start?


Start by reading http://php.net/dochowto
Specifically chapter 11 -

  http://doc.php.net/php/dochowto/chapter-user-notes.php

That should everyone here some insight into the user notes process.


I do have one reservation, though...

Last time I tried to do something like this, I ended up having a hard
drive with what felt like Gigabytes of PHP Doc source code from CVS
(which was an adventure in itself back then) and then had to attempt
to run software that chewed up so much RAM/CPU and never managed to
actually get useful output before crashing from lack of resources.

Granted, this was a decade ago, and my hardware was pretty crappy at
the time...  Not that I've got much better gear now, mind you. :-)

I'm guessing though that these days, it's just a web form somewhere. 
I can handle that. :-)


For just auditing notes, you can do it via a web form, yes.  And now 
with livedocs, you can get instant feedback if you want to progress to 
actually work on the main manual pages themselves.  The above howto


-Rasmus

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



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Rasmus Lerdorf

Martin Alterisio wrote:

Maybe you can read the contents of the feeds using fsockopen() and
stream_set_timeout() to adjust the timeout, or stream_set_blocking()
to read it asynchronously, and then load the xml with
simplexml_load_string().

PS: I forgot to reply to all and mention you'll have to send the GET
http command and headers, check the php manual for examples.


You can just use fopen() to avoid all that.

eg.

$fd = fopen($url);
stream_set_blocking($fd,true);
stream_set_timeout($fd, 5);  // 5-second timeout
$data = stream_get_contents($fd);
$status = stream_get_meta_data($fd);
if($status['timed_out']) echo Time out;
else {
  $xml = simplexml_load_string($data);
}

As for your caching, make sure you create the cache file atomically.  So 
how about this:


function request_cache($url, $dest_file, $ctimeout=60, $rtimeout=5) {
  if(!file_exists($dest_file) || filemtime($dest_file)  
(time()-$ctimeout)) {

$stream = fopen($url,'r');
stream_set_blocking($stream,true);
stream_set_timeout($stream, $rtimeout);
$tmpf = tempnam('/tmp','YWS');
file_put_contents($tmpf, $stream);
fclose($stream);
rename($tmpf, $dest_file);
  }
}

That takes the url to your feed, a destination file to cache to, a cache 
timeout (as in, fetch from the feed if the cache is older than 60 
seconds) and finally the request timeout.


Note the file_put_contents of the stream straight to disk, so you don't 
ever suck the file into memory.  You can then use a SAX parser like 
xmlreader on it and your memory usage will be minimal.  You will need 
PHP 5.1.x for this to work.


You could also use apc_store/fetch and skip the disk copy altogether.

(untested and typed up during a long boring meeting, so play with it a bit)

-Rasmus

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



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Rasmus Lerdorf

Richard Lynch wrote:

On Mon, April 10, 2006 6:17 pm, Rasmus Lerdorf wrote:

Martin Alterisio wrote:

Maybe you can read the contents of the feeds using fsockopen() and
stream_set_timeout() to adjust the timeout, or stream_set_blocking()
to read it asynchronously, and then load the xml with
simplexml_load_string().

PS: I forgot to reply to all and mention you'll have to send the GET
http command and headers, check the php manual for examples.

You can just use fopen() to avoid all that.


No, he can't.

Sorry, Rasmus. :-)

If the URL is not working at the time of fopen() then you'll sit there
spinning your wheels waiting for fopen() itself to timeout, before you
ever GET a valid file handle to which one can apply stream_set_timeout
and/or stream_set_blocking.


I thought it was the case of an overloaded slow-responding server, not 
one that is down.  For the initial connection just set your 
default_socket_timeout appropriately if you are not happy with the default.


So you just add 1 line to my example:

function request_cache($url, $dest_file, $ctimeout=60, $rtimeout=5) {
  if(!file_exists($dest_file) || filemtime($dest_file)  
(time()-$ctimeout)) {

ini_set('default_socket_timeout',$rtimeout);
$stream = fopen($url,'r');
stream_set_blocking($stream,true);
stream_set_timeout($stream, $rtimeout);
$tmpf = tempnam('/tmp','YWS');
file_put_contents($tmpf, $stream);
fclose($stream);
rename($tmpf, $dest_file);
  }
}

Problem solved.

-Rasmus

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



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Rasmus Lerdorf

Richard Lynch wrote:

It would be REALLY NIFTY if fopen and friends which understand all
those protocols of HTTP FTP HTTPS and so on, allowed one to set a
timeout for URLs, but they don't and nobody with the skills to change
that (not me) seems even mildly interested. :-( :-( :-(


Because it is already there and has been since Sept.23 2002 when it was 
added.


-Rasmus

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



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Rasmus Lerdorf

Richard Lynch wrote:

On Mon, April 10, 2006 4:46 pm, darren kirby wrote:

quoth the Robert Cummings:

Why do you do this on every request? Why not have a cron job
retrieve an
update every 20 minutes or whatnot and stuff it into a database
table
for your page to access? Then if the cron fails to retrieve the feed
it
can just leave the table as is, and your visitors can happily view
slightly outdated feeds? Additionally this will be so much faster
that
your users might even hang around on your site :)

This is a very interesting idea, but I am not sure if it is suitable
for me at
this point. First of all, one feed in particular can change in a
matter of
seconds, and I do want it to be as up to date as possible. Secondly,
this is
just for my personal site which is very low traffic, and it is not
inconceivable that getting the feed every 20 minutes by cron would be
_more_
taxing on the network than simply grabbing it per request...


Perhaps, then, you should:
maintain a list of URLs and acceptable age of feed.
Attempt to snag the new content upon visit, if the content is old
Show the old content if the feed takes longer than X seconds.

You'll STILL need a timeout, which, unfortunately, means you are stuck
rolling your own solution with http://php.net/fsockopen because all
the simple solutions pretty much suck in terms of network timeout.
:-(

It would be REALLY NIFTY if fopen and friends which understand all
those protocols of HTTP FTP HTTPS and so on, allowed one to set a
timeout for URLs, but they don't and nobody with the skills to change
that (not me) seems even mildly interested. :-( :-( :-(

Since I've already written a class that does something like what you
want, or maybe even exactly what you want, I might as well just
provide the source, eh?

http://l-i-e.com/FeedMulti/FeedMulti.phps


No stream_select() ?

Here is an example Wez wrote years ago:

?php
$hosts = array(host1.sample.com, host2.sample.com, host3.sample.com);
$timeout = 15;
$status = array();
$sockets = array();

/* Initiate connections to all the hosts simultaneously */
foreach ($hosts as $id = $host) {
$s = stream_socket_client($host:80, $errno, $errstr, $timeout,
STREAM_CLIENT_ASYNC_CONNECT);

if ($s) {
$sockets[$id] = $s;
$status[$id] = in progress;
} else {
$status[$id] = failed, $errno $errstr;
}
}

/* Now, wait for the results to come back in */
while (count($sockets)) {
$read = $write = $sockets;
/* This is the magic function - explained below */
$n = stream_select($read, $write, $e = null, $timeout);

if ($n  0) {
/* readable sockets either have data for us, or are failed
 * connection attempts */
foreach ($read as $r) {
$id = array_search($r, $sockets);
$data = fread($r, 8192);
if (strlen($data) == 0) {
if ($status[$id] == in progress) {
$status[$id] = failed to connect;
}
fclose($r);
unset($sockets[$id]);
} else {
$status[$id] .= $data;
}
}
/* writeable sockets can accept an HTTP request */
foreach ($write as $w) {
$id = array_search($w, $sockets);
fwrite($w, HEAD / HTTP/1.0\r\nHost: 
. $hosts[$id] .  \r\n\r\n);
$status[$id] = waiting for response;
}
} else {
/* timed out waiting; assume that all hosts associated
 * with $sockets are faulty */
foreach ($sockets as $id = $s) {
$status[$id] = timed out  . $status[$id];
}
break;
}
}

foreach ($hosts as $id = $host) {
echo Host: $host\n;
echo Status:  . $status[$id] . \n\n;
}
?

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



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Rasmus Lerdorf

Robert Cummings wrote:

On Mon, 2006-04-10 at 23:11, Richard Lynch wrote:

On Mon, April 10, 2006 9:59 pm, Rasmus Lerdorf wrote:

Richard Lynch wrote:

It would be REALLY NIFTY if fopen and friends which understand all
those protocols of HTTP FTP HTTPS and so on, allowed one to set a
timeout for URLs, but they don't and nobody with the skills to
change
that (not me) seems even mildly interested. :-( :-( :-(

Because it is already there and has been since Sept.23 2002 when it
was
added.

I've added a Note to 'fopen' so maybe others won't completely miss
this feature and look as foolish as I do right now. :-)


If it's anything like the helpful note I added about using copy( source,
dest ) where dest accidentally points to source (due to linking), you'll
get a nice retarded email like the following:


You could volunteer to help maintain the user notes.  It it thankless 
and tedious work to keep up with the flood of user notes being 
submitted.  A huge percentage of them being either spam, product pitches 
or really dumb questions.  The fact that occasionally a useful note gets 
deleted by mistake doesn't surprise me.


-Rasmus

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



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Rasmus Lerdorf

Robert Cummings wrote:

On Mon, 2006-04-10 at 23:24, Rasmus Lerdorf wrote:

Robert Cummings wrote:

On Mon, 2006-04-10 at 23:11, Richard Lynch wrote:

On Mon, April 10, 2006 9:59 pm, Rasmus Lerdorf wrote:

Richard Lynch wrote:

It would be REALLY NIFTY if fopen and friends which understand all
those protocols of HTTP FTP HTTPS and so on, allowed one to set a
timeout for URLs, but they don't and nobody with the skills to
change
that (not me) seems even mildly interested. :-( :-( :-(

Because it is already there and has been since Sept.23 2002 when it
was
added.

I've added a Note to 'fopen' so maybe others won't completely miss
this feature and look as foolish as I do right now. :-)

If it's anything like the helpful note I added about using copy( source,
dest ) where dest accidentally points to source (due to linking), you'll
get a nice retarded email like the following:
You could volunteer to help maintain the user notes.  It it thankless 
and tedious work to keep up with the flood of user notes being 
submitted.


I'll keep that in mind for the future when I have more free time (2 kids
under 3 is good for keeping me occupied beyond work atm :).

  A huge percentage of them being either spam, product pitches 
or really dumb questions.  The fact that occasionally a useful note gets 
deleted by mistake doesn't surprise me.


Point taken, just sort of feels like  slap in the face after you go to
the effort to write a useful note :)


Yes, but just keep in mind that the folks on the other end make the 
effort every single day to cull through hundreds of these.  We have 
small kids and real jobs as well.  I am typing this with a 4-year old 
sitting in my lap doing his best to make a dinosaur stomp on my keys. 
So while I sympathize with the fact that the work you put into this note 
wasn't appreciated, please recognize that you are not being very 
appreciative of the hundreds of hours of work the folks on the other end 
are putting in.  In general the user notes in the manual are useful. 
There isn't much spam, and when something slips through it gets caught 
rather quickly.  This stuff doesn't happen by itself.


-Rasmus

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



Re: [PHP] Date problems

2006-04-09 Thread Rasmus Lerdorf

Satyam wrote:
Timestamps are stored as seconds from a certain date.  The base date 
differ depending on the platform, Windows use 1/1/1980 the rest 
1/1/1970, but still seconds.  7 days are 7*24*60*60.  Just add that much 
to a timestamp.  It helps having a constant such as:


define ('DAY_IN_SECONDS',86400);


The problem with doing it this way is that it won't take leap seconds, 
leap years and daylight savings into account, so on any of these edge 
cases it will appear to be broken.  That's why strtotime(+7 days) is 
the correct way to do this.


-Rasmus

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



Re: [PHP] Ajax please....

2006-04-08 Thread Rasmus Lerdorf

Rasmus Lerdorf wrote:

?php
if(!empty($_POST['loc'])) {
  $src = 
http://api.local.yahoo.com/MapsService/V1/mapImage?appid=YahooDemo;;

  $src.= location=.urlencode($_GET['loc']).
 output=phpimage_width=300image_height=300zoom=7;
  header(Content-type: application/x-json);
  echo json_encode(unserialize(file_get_contents($src)));
  exit;
}
?


Typo in the above.  $_GET['loc'] should be $_POST['loc'].  I switched 
from GET to POST and missed this one.  The next version of the Yahoo 
libs coming out soon will have GET support.  My previous example was a 
touch ahead of the released version.


-Rasmus

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



Re: [PHP] Date problems

2006-04-08 Thread Rasmus Lerdorf

Mace Eliason wrote:

Hi,

I am having troubles adding 7 days to the current date.  I have been 
reading through php.net date() and this is what I have come up with but 
it doesn't work

$today = date('m/d/Y');
$nextweek = date('m/d/Y',mktime(date(m), date(d)+7, date(Y)));

if I echo the above variables they are the same? Shouldn't the $nextweek 
be different?


You are thinking too much!  ;)

$nextweek = date(m/d/Y,strtotime(+7 days));

-Rasmus

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



Re: [PHP] Date problems

2006-04-08 Thread Rasmus Lerdorf

Rasmus Lerdorf wrote:

Mace Eliason wrote:

Hi,

I am having troubles adding 7 days to the current date.  I have been 
reading through php.net date() and this is what I have come up with 
but it doesn't work

$today = date('m/d/Y');
$nextweek = date('m/d/Y',mktime(date(m), date(d)+7, date(Y)));

if I echo the above variables they are the same? Shouldn't the 
$nextweek be different?


You are thinking too much!  ;)

$nextweek = date(m/d/Y,strtotime(+7 days));


By the way, the reason your way isn't working is because you have your 
arguments wrong.  The first three arguments to mktime are hour, minute, 
second, and since you are only printing the date you lose the fact that 
you added 7 minutes.  If you try your script just before midnight you 
will notice the values are different.


-Rasmus

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



Re: [PHP] Ajax please....

2006-04-07 Thread Rasmus Lerdorf

Ryan A wrote:

Just been googleing and trying out different AJAX frameworks..:

From PEAR HTML_AJAX

Gauva
My-Bic
AjaxAC
and quite a few moreand it happened, I confused myself :-(

For some reason HTML_AJAX is not working on my local machine (windows based,
I am getting runtime errors with the examples) and it seems quite
bulky. I have even tried the YAHOO one, which Rasmus suggested to another
guy some time back (found it
after looking in the archives) unfortunatly could not find much
documentation that I could understand...


It's really not hard.  Remember my 30s AJAX post a while back?  Well, 
here is a revised version using the Yahoo! library.  You can try it on 
this slide:


  http://talks.php.net/show/yul/14

There are basically 3 parts to any AJAX app.  The initial HTML that the 
user first loads up.  In this case it is:


 form name=main action=javascript:sendform('yajax.php','main')
   Location: input type=text name=loc /
 /form

So, just a form with a single text field where the user can enter a 
location.  Easy enough so far.  When the user hits enter the action line 
there says to call the sendform() Javascript function and pass it the 
strings 'yajax.php' and 'main'.  'yajax.php' is the name of the script 
to post to and 'main' is the name of the form that contains the data to 
post.


Ok, now to the second part, the Javascript portion that implements this 
sendform() function using the Yahoo libs.  You could have this in a 
separate .js file, but to keep it simple I have just put it into the 
same file in the head section:


 script language=javascript src=/yui/YAHOO.js/script
 script language=javascript src=/yui/connection.js/script
 script language=javascript
!--
var fN = function callBack(o) {
  var resp = eval('(' + o.responseText + ')');
  img = document.createElement('img');
  img.src = resp.Result; img.width=300; img.height=300; img.border=1;
  document.body.appendChild(img);
}
var callback = { success:fN }
function sendform(target,formName) {
   YAHOO.util.Connect.setForm(formName);
   YAHOO.util.Connect.asyncRequest('POST',target,callback);
}
// --
 /script

This might look a bit complex, but the first part just includes the 
Yahoo stuff.  YAHOO.js and connection.js which are part of the ZIP file 
you can get from here: http://developer.yahoo.com/yui/downloads/yui.zip
Next we have the callback function that will be called when we receive 
data back from the server.  This does an eval() which is simple, but if 
you don't trust your source you might want to use 
http://www.json.org/js.html instead.  After parsing the returned json we 
create an IMG tag, set some attributes on it and append it to the 
document body.  And finally the sendform function is a simple 2-liner 
that goes and fetches the form data from the passed in formName followed 
by the asynchronous backend request to the server.


The final part is the really easy part.  The server-side PHP part.

?php
if(!empty($_POST['loc'])) {
  $src = 
http://api.local.yahoo.com/MapsService/V1/mapImage?appid=YahooDemo;;

  $src.= location=.urlencode($_GET['loc']).
 output=phpimage_width=300image_height=300zoom=7;
  header(Content-type: application/x-json);
  echo json_encode(unserialize(file_get_contents($src)));
  exit;
}
?

This makes a call to the Yahoo! map image api to get a map tile for the 
location the user entered and it returns the image url json-encoded. 
You will need the pecl/json extension installed do this encoding or 
failing that there is a PEAR JSON as well.


You are not going to be able to avoid writing a little bit of Javascript 
if you are going to do asynchronous backend requests (AJAX).  You need 
to send the request somehow from Javascript and you need to read the 
response in Javascript.  On the other hand, it is mostly just DOM 
manipulation so if you know DOM in PHP it isn't hard to pick up.


-Rasmus

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



Re: [PHP] parsing malformed xml documents

2006-04-04 Thread Rasmus Lerdorf

Mariano Guadagnini wrote:

Hei guys,
I´m parsing some xml's and fetching nodes using xpath, and the PHP 5.0 
DOM. Unfortunately, some documents have white spaces in the beginning or 
some missing tags. In some situations, the script just skips that xml, 
or even crashes without notice. I tried loading them as html, and 
disabling validation, but that didn´t do the trick, as they have invalid 
html tags.
I wonder if there is some way (maybe an external class, or something) to 
accomplish this. I know that theorically, it would be better to have 
well formed xml (I also think so), but I need to handle them at any 
rate, and they´re created by an external source away from my control.


How about something like this:

  $dom = @DOMDocument::loadHTML($xml);
  if(is_object($dom)) $xpath = new DOMXPath($dom);
  else {
$xml = tidy_repair_string($xml);
if($xml) {
$dom = @DOMDocument::loadHTML($xml);
if(is_object($dom)) $xpath = new DOMXPath($dom);
}
  }

-Rasmus

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



Re: [PHP] Re: PHP AJAX Framework - Suggestions Please

2006-04-03 Thread Rasmus Lerdorf

Ruben Rubio Rey wrote:

The best and simplest for me is prototype.js

Is much more than ajax ! 100% cross browser! ang GPL!

http://www.sergiopereira.com/articles/prototype.js.html


Note that quite a few people who know a lot about Javascript really 
don't like the fact that prototype.js extends the basic Array type. 
This means that if you have any Javascript that isn't prototype.js 
aware, chances are pretty good that it will break because, for example, 
you can't iterate over the elements of an Array anymore.  It also 
doesn't namespace any of its symbols which again means it doesn't play 
nice with others.  And my last real gripe is that it is a single 
monolithic library.  It's all or nothing.


I am of course rather biased, but I strongly prefer the Yahoo! User 
Interface Library.  You can read about it here:


  http://developer.yahoo.com/yui/

It is a set of tiny standalone components that won't in any way 
interfere with any other Javascript code you might have and you can pick 
and choose just the things you need.


-Rasmus

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



Re: [PHP] PDO, Persistent Connections

2006-03-28 Thread Rasmus Lerdorf

Philip Thompson wrote:

On Mar 28, 2006, at 10:23 AM, Jochem Maas wrote:


Jarratt Ingram wrote:

Hi,
I have a little unusual question, we are currently looking into the 
new PDO
extension with PHP5.1. We are currently use Mysql, InnoDB and 
transactions.

What we would like to know if we use the PDO extension and persistent
connections, can we start a Transaction on one page and then commit 
it from
another separate page by carrying the PDO object through a php 
session? Thus
preventing php from automatically closing that specific DB 
connection.  The

reason for this we use remote connections to the Database.
Any thoughts or comments if i have missed the boat completely


not quite but in practice what you want is not possible.
in order to continue that transaction on 'page 2' you browser will
need to connect to the same thread/process as the connection of request
of 'page 1' - not impossible but it's _very_ hit and miss (not 
something you

want to build upon).

oh and php resource datatypes (e.g. a DB connection) cannot be 
serialized.


in short you don't want to to do what you think you want to do :-) 
instead
stuff the data in the session until you have it all and only then 
start and finish

the transaction in a single request.


Regards
Jarratt



*Please don't throw tomatoes at me!!*

Sounds like Java might be a solution here. From my understanding, Java 
can hold persistent connections. I know that may not be a feasible 
solution, but still something to consider.


Not in any sort of scalable fashion.

In order to do this with either Java or PHP the second request has to 
come in on the same machine and get the same database connection as in 
the initial request.  While you could do some sticky session tricks and 
some database pooling, connection holding magic, there is no way this 
will work at all at any sort of scale.  What happens, for example, if 
that second request never comes?  How long do you keep that 
half-finished transaction connection around?  You obviously can't give 
it to anybody else, so it is in limbo.


The difference between Java and PHP here is that Java has a single JVM 
process per machine that holds the pool of database connections, so in a 
single-server architecture it becomes easier to give subsequent requests 
the same database connection, but as far as I am concerned that just 
means it is easier to shoot yourself in the foot since this is really a 
bad way to approach this.


-Rasmus

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



Re: [PHP] Why Should I Use Zend Optimizer?

2006-03-27 Thread Rasmus Lerdorf

Ray Hauge wrote:
Still right on with the pre-compiling though ;)  I find that the Optimizer has 
value.  If you wanted to cache on top of that you could probably speed it up 
even further with cached responses (APC or I think Zend has one too)


Without an opcode cache, using the optimizer is going to slow you down 
unless you have written some extraordinarily dumb code.  Without an 
optimizer the compiler translates your PHP script into a set of opcodes 
which are passed to the executor to be executed.  The optimizer inserts 
itself in between these two stages and does a pass across the opcodes 
trying to remove and possibly re-arrange things a bit to make them 
execute faster.  But if you are not caching this optimized set of 
opcodes in an opcode cache, then the work to optimize the opcodes will 
in almost all cases far outweigh the performance benefits you might see 
in the executor.


-Rasmus

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



Re: [PHP] Switching to UTF-8. Need help.

2006-03-23 Thread Rasmus Lerdorf

Andy wrote:
Hi to all, 

We are developing a multilanguage application, and slowly it seems that the Latin1(ISO 5589 1) encoding is not enough. 
I tried simply to convert the database and the encoding of the php to UTF-8, but I'm getting some problems. 

If I make an echo 'möbel, Belgien' the browser does not show me the correct character. If I look in the source of the document the character is good. Default encoding of the browser is UTF-8. If I change manually the browser encoding then the chars are showed correclty. 

We have a lot of defines with fix texts, which are full with german and french characters. Any of these aren't shower correctly. 


What is the workaround for this?


In your php.ini file, use:

default_charset = utf-8

-Rasmus

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



Re: [PHP] no newline after ? in the resulting HTML

2006-03-18 Thread Rasmus Lerdorf

Brady Mitchell wrote:

Why there is no newline afer  pHello World/p ?
Is it a PHP bug or the tutorial should be updated?


The tutorial is fine.

The sample code mentioned:

html
 head
  titlePHP Test/title
 /head
 body
 ?php echo 'pHello World/p'; ?
/body
/html 


Contains a line break after the pHello World/p is echoed .
 
Check your code, if you don't have that line break, PHP is not going to create it for you.


That's actually not true.  A line break after a closing ? is ignored. 
This is to make it possible to have something like this:


?php /* do something */ ?
html
...
/html

And have that opening html tag be on the first line of the file.

Another reason is for include files.  If you include a file that ends 
with ?newline then you normally don't want that newline.  Having a 
newline output for each file you include doesn't make much sense.


So yes, technically the tutorial is wrong.

-Rasmus

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



Re: [PHP] no newline after ? in the resulting HTML

2006-03-18 Thread Rasmus Lerdorf

Adrian wrote:

Is there a way to circumvent this?
My template engine compiles templates to PHP files and this feature
makes the output html code look awful sometimes.


Nope.  Put in an extra newline after ? if you need them, or put a \n at 
the end of the last echo inside the PHP block.


-Rasmus

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



Re: [PHP] no newline after ? in the resulting HTML

2006-03-18 Thread Rasmus Lerdorf

Rostislav Krasny wrote:

On Sat, 18 Mar 2006 13:49:19 -0800
[EMAIL PROTECTED] (Jim Lucas) wrote:


put a space after the ? and you will retain the line feed


It also adds that space before the retained line feed, but so it looks
better anyway. Excellent suggestion, thank you! Could it be added to
the FAQ and to the official PHP tutorial? At least to the discussed
part of the tutorial, so PHP beginners like me wouldn't be confused :-)


I added it to the tutorial.  It will show up the next time the manual is 
built.


-Rasmus

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



Re: [PHP] Re: Possible hacker using php script to send e-mails?

2006-03-11 Thread Rasmus Lerdorf

Manuel Lemos wrote:

Hello,

on 03/11/2006 09:39 AM Merlin said the following:

I am running php 4.x on a suse 9.x machine. There is a php script which
resides
on a webapp that is responsible for sending e-mail to myself in case of
errors like db-errors or similar. Called error.php
This script does include phpmailer and uses it to send the e-mails to me.
Now I am receiving on the e-mail specified as TO: e-mails with different
subject
than specified and different text?! All english text with wired
sentences, must be a bot or so. How is this possible? The subject line
is fixed and right after that commend send is executed. So no idea how
they do it and how I can prevent it. It looks like this:
$mail-Subject = 'Fehlerbericht';
$mail-Send();
How is it possible that they change this subject line? I checked the
server log and each time an e-mail has been sent to me of that kind
there is a logentry in apache log that says that this script has been
executed. So the e-mails definatelly come from that script?!


If you are setting message headers with untrusted values that may
contain line breaks, that is your problem. Line breaks make mail systems
interpret the next line as a new header. That header may be used to
inject new recipients for instance using Bcc: .

You can have line breaks in header but you need to escape them properly
so they are interpreted as continuation lines rather than new headers.


That is only true for the additional_headers (4th) argument to the mail 
function.  That argument is specifically for doing free-form headers, so 
as long as you only use the to, subject and message arguments to the 
mail function you are safe.


-Rasmus

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



Re: [PHP] Re: APC and PHP 5.1.2

2006-03-03 Thread Rasmus Lerdorf

Jens Kleikamp wrote:

steve wrote:

Thanks for that! It meant that I should look in other directions which
helped me figure out the problem. Can you try again with:

apc.optimization=1




Your script also seems to work on my sytem with optimization=1.


The optimizer doesn't work very well at this point.  It will get some 
attention soon I hope.


If you need to squeeze every bit of performance out of your code there 
are usually much bigger wins than an optimizer will give you in going 
through and cleaning things up.  The easy list of low-hanging 
optimization fruit are:


1. Check your include_path and your includes.  If you make heavy use of
   files in a directory on your include_path, make sure that path is
   first.  And yes, that means before . as well.  In fact I wouldn't
   even put . in your include_path, just use

  include './file.php';

   if you want to include from the current directory or relative to
   the current directory.  You are going to save quite a few stat calls
   by cleaning this up.

2. Minimize your use of include_once/require_once.  If you can clean
   up your dependencies and your include tree such that there is no
   question of double-inclusion anywhere everything will be much
   happier.  A redundant include is obviously going to waste useless
   cycles, but even if you don't hit the redundant case, the _once
   operations are optimized for the non-cached scenario and actually
   calls open() on every file which makes sense without an opcode cache
   because you are going to need the file opened, but with a cache you
   are going to get the opcodes from the cache and this becomes a
   useless extra open() syscall.

3. Try to avoid pushing things out of the compiler and into the
   executor.  That's a bit cryptic, but it basically means try to
   avoid dynamically defining functions and classes.

Good:  ?php  class foo { ... } ?

Bad:   ?php
 if($some_condition) {
   class foo { ... }
 }
   ?

   In the second case the foo class has to be defined at script runtime
   which is much slower than if it is unconditionally defined in the
   compiler.  Without an opcode cache this isn't much of an issue, of
   course since you have to run both stages, but with an opcode cache
   where you skip the compile phase and just feed the opcodes straight
   to the executor, the more you can handle when you compile the opcodes
   the faster your script will run because the executor has less work to
   do.

4. Make use of APC's apc_store/apc_fetch mechanism.  If you have any
   sort of large array of data you need often, stick it in shared memory
   with an apc_store() call.  For example, a typical thing you see in
   PHP applications is some sort of config.php file.  It might look
   like this:

?php
   $config['db_type'] = 'mysql';
   $config['db_user'] = 'bob';
   $config['db_pswd'] = 'foobar';
   $config['data_dir'] = '/var/www/app_data';
   ...
?

   And then on every page you have:  include './config.php';

   This is very inefficient even though the actual file will be cached
   in the opcode cache, it still has to execute and create the array.
   You can cache the created array like this:

if(!$config = apc_fetch('config')) {
   include './config.php';
   apc_store('config',$config);
}

   Here we only include the config file and thus create the $config
   array if it isn't in the cache.  So this will only happen on the
   very first request.  From then on it will get pulled from the
   shared memory cache.

   If you look around there are usually a couple of candidates for
   this sort of caching in every application and it can make quite
   a difference for large arrays.  Try to avoid caching objects
   because they need to be serialized and unserialized in and out
   of the cache and you can only cache the properties anyway, so
   pull the data you want to cache into an array and cache that.

-Rasmus

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



Re: [PHP] APC and PHP 5.1.2

2006-03-02 Thread Rasmus Lerdorf

steve wrote:

I can't get APC 3.0.8 to work on anything, at all. On Windows, it
crashes the server, and on Linux, it can't handle objects. For
example:

?php

class abc {
}

$a = new abc;

var_dump($a);

?

Gives:

NULL

Any idea on what is going on?


Use the CVS version.  I need to push a new version out soon.

cvs -d :pserver:[EMAIL PROTECTED]:/repository login
Password: phpfi
cvs -d :pserver:[EMAIL PROTECTED]:/repository co pecl/apc
cd pecl/apc
phpize
./configure --enable-apc-mmap --with-apxs=/usr/local/bin/apxs \
--with-php-config=/usr/local/bin/php-config
make
make install

(and restart your web server)

-Rasmus

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



Re: [PHP] APC and PHP 5.1.2

2006-03-02 Thread Rasmus Lerdorf

steve wrote:

OK, will try. Does this work in the CVS version?

?php
error_reporting(E_ALL);
class A
{
public $_t = 'something';
public function __get($name)
{
$getter='get'.$name;
if(method_exists($this,$getter))
{
// getting a property
return $this-$getter();
}
}

public function getTest()
{
return 'OK';
}
}
$result='';
$one = new A();
var_dump($one);
echo BRTest \$one-getTest(): ;
echo $one-getTest();
echo BRTest \$one-Test: ;
echo $one-Test;
echo BRTest with eval: ;
eval ('$result = $one-Test; ');
echo $result;
echo BRTesting done.;


It outputs:
object(A)#1 (1) { [_t]=  string(9) something }
Test $one-getTest(): OK
Test $one-Test: OK
Test with eval: OK
Testing done.

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



Re: [PHP] APC and PHP 5.1.2

2006-03-02 Thread Rasmus Lerdorf

steve wrote:

OK, got it and installed it (checked the output of phpinfo to
confirm), and I get this on both the first load (uncached) and later
loads (cached):

NULL
Test $one-getTest():

With an error in the error log telling me I'm a dope for dereferencing
a null object.

Why does the weird stuff always happen to me?

Without APC it runs fine. I'm using Fastcgi version if that matters.


It probably does.  I have never tried it against the Fastcgi sapi.  Try 
it with the Apache module version to rule this out.


-Rasmus

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



Re: [PHP] Floored!

2006-02-24 Thread Rasmus Lerdorf

Ben Miller wrote:

If anyone has an answer for this, I would be greatly appreciative.

I was trying to compare two values, the first is the total cost of products
to be refunded, and the second is the original order total.  To the naked
eye, they both were coming out as 102.85, yet an if($Refund_Amount 
$Order_Total) was coming back true, so.

I ran some tests, and did the following:

$Order_Total = sprintf(%01.20f,$Order_Total);
$Refund_Amount = sprintf(%01.20f,$Refund_Amount);

which produced:

$Order_Total = 102.84431566
and $Refund_Amount = 102.85852651

so, I figured I would try the following to make sure that the figures in the
database weren't weird:

$Bar = 102.85;
$Foo = sprintf(%01.20f,$Bar);

echo \$Foo = $Foo;

which produced:

$Foo = 102.84431566;

I am completely lost.


Read the note on floating point precision here:

  http://us3.php.net/manual/en/language.types.float.php

You need to either work completely in pennies and only convert to 
dollars for display purposes so you are always working with integers, or 
you need to introduce a little fuzz factor whenever you are doing 
operations on floating point values.


There is simply no way for a computer to accurately represent a fraction 
with anything other than an estimation.  The typical fix if you don't 
want to switch to using integer math is to add an appropriate fuzz 
factor.  Like this:


  $fuzz = 0.001;
  if(floor($value+$fuzz) == 10) ...

That is, if the floating point $value happens to be 9.999 or 
10.001 then applying this fuzz factor and doing the floor 
operation, you will always get 10 as long as your fuzz factor is larger 
than the precision error of your machine.


-Rasmus

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



Re: [PHP] Can php.ini include another config file

2006-02-23 Thread Rasmus Lerdorf

Khai wrote:
In my development environment I have Zend Debugger / Zend Studio 
installed.  I like to put all the directives for this into studio.ini, 
and include this file into the main php.ini somehow.  Is this possible? 
 Also can I put php directives into the apache httpd.conf file?


No, you can't chain ini files like that, but you can build your PHP using:

--with-config-file-scan-dir=/etc/php

Then any .ini file you put in /etc/php will be parsed in alphabetical 
order.


-Rasmus

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



Re: [PHP] Does anyone here use the pecl extension APC?

2005-11-17 Thread Rasmus Lerdorf
Filing a bug against APC with a gdb backtrace from one of these crashes would 
be useful.  
See http://pecl.php.net/bugs/report.php?package=APC

-Rasmus

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



Re: [PHP] serializing result sets or what?

2005-09-28 Thread Rasmus Lerdorf
 A very similar question was asked recently on this list. You might like 
 to consider caching whatever you create from those result sets rather 
 than the result sets themselves, but APC [1] is worth looking at as I 
 believe it can cache (some?) PHP vars without serialisation, using 
 apc_store() and apc_fetch().

Everything except objects.  That also means if you have a nested array 
containing objects, it will have problems.  Right now you have to serialize
the object yourself if you want to cache it, but I will add code soon to do
that automatically internally.

-Rasmus

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



Re: [PHP] cache xml objects in php5

2005-09-27 Thread Rasmus Lerdorf
Kevin Wang wrote:
 My php5 web application needs to parse/marshall a bunch of large xml files 
 into
 php5 objects at the beginning of handling each request.  These xml files are
 static across all the requests and it is really time consuming to
 parse/marshall them into php5 objects.

What sort of PHP 5 objects?  Do you mean simplexml objects, or do you mean 
dom objects?

 I am wondering if there is any means to cache these xml objects so that each
 request will not go through the same time consuming xml parsing/building
 operation.  Serialization doesn't work in my case as deserialization is also
 very expensive.
 
 I am using Apache as the web server.  What I am thinking is that if php5 
 allows
 us to keep certain objects (and their references) around across all the
 requests in a child process instead of cleaning all the object memory every
 time after a script/request is finished.

Generally the best way to do this is to parse the data down closer to its final 
usage.
Typically the final thing you need is not a simplexml or a dom object, what you 
really
need is structured data and this can typically be represented with an 
associative
array.  Once you have it down to an array, you can use pecl/apc and its 
apc_store()/
apc_fetch() functions to cache these in shared memory without the slowdown of 
serialization.  A decent example of this technique can be found in the little 
simple_rss
function I wrote a while ago which parses all sorts of RSS feeds into a nested 
array and
caches this final array in shared memory using APC.

There really is no decent way to cache an object in shared memory without 
serialization.
The simpler data types can however be cached with APC.  Making them persistent 
is also
a problem as it completely violates PHP's request sandbox concept.  If you 
really feel
you need this, write yourself a PHP extension and initialize these objects in 
your MINIT
hook so they only get loaded at server startup and they will be available for 
the life of
that process.  

Jasper Bryant-Greene wrote:
 Have you looked at memcache?
 http://www.php.net/manual/en/ref.memcache.php

 You install and run the memcached server (it can be on localhost for a 
 single server setup, or for many servers it can be shared if the 
 interconnects are fast enough). Then you can cache just about any PHP 
 variable, including objects, in memory.

He did say that serialization wasn't an option and you can't use memcached 
without serializing.  You may not realize you are serializing, but the memcache
extension serializes internally.  There was also no mention of needing to cache
across servers here.

-Rasmus (attempting to use the new Yahoo! Mail webmail for php-general)

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



Re: [PHP] Re: cache xml objects in php5

2005-09-27 Thread Rasmus Lerdorf
 I guess to only way to solve my problem is to write my own extension to
 initialize my objects in my own memory (even can keep them in local memory, as
 long as they are persistent across requests).  You mentioned to write a MINIT
 hook; could you give some more details?  Is there any documentation or
 available sample extensions that I can start with?

Every extension in the ext/ directory of the PHP sources is an example.  Also 
look at pecl/*

Al read README.EXT_SKEL and README.PARAMETER_PARSING_API in the PHP sources.

-Rasmus

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



Re: [PHP] Problems with headers

2005-09-22 Thread Rasmus Lerdorf
Graham Anderson wrote:
 ?php
 $quote = \;
 $xml = '';
 $xml .= '?xml version=1.0?'.\n;
 $xml .= '?quicktime type=application/x-qtskin?'.\n;
 $xml .= 'skin'.\n;
 $xml .= 'movie src=' . $quote.   ../../fonovisa.mov .  $quote. 
 '/'.\n;
 $xml .= 'contentregion src=' .$quote.  ../images/mask.gif .
 $quote.   '/'.\n;
 $xml .= 'dragregion src=' .  $quote. ../images/drag.gif .   $quote.  
  '/'.\n;
 $xml .= '/skin';
 header('Content-Type: video/quicktime'); //took out a space
 header (Content-Length: .strlen($xml));  // added a space
 echo $xml;
 ?

Wow, that is nasty.  There is probably a syntax error in there.  Use a
heredoc in cases like this.  Something like this:

$xml =  EOB
?xml version=1.0?
?quicktime type=...
...
EOB;

Much less likely to make mistakes this way since you don't need to
escape anything (except $) and you can still use variables in the block
of text.

-Rasmus

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



Re: [PHP] Problems with headers

2005-09-22 Thread Rasmus Lerdorf
Graham Anderson wrote:
 Thanks Rasmus :)
 that is an incredibly cool tip: EOB
 Surprised I did not see you at the Digital Rights [hollywood digital]
 conference in LA early this week.
 Upside: Free sushi and an ocean view. Downside: Lots of 'agency' types
 and sales folk
 
 
 when  I access a straight movie file with no php, fonovisa.mov,
 everything looks good when I curl it
 HTTP/1.1 200 OK
 Date: Thu, 22 Sep 2005 16:52:45 GMT
 Server: Apache/1.3.33 (Unix) PHP/4.4.0 FrontPage/5.0.2.2510
 Last-Modified: Tue, 20 Sep 2005 17:58:39 GMT
 ETag: 1b28dcc-e3-43304dcf
 Accept-Ranges: bytes
 Content-Length: 227
 Content-Type: video/quicktime
 
 * Connection #0 left intact
 * Closing connection #0
 ?xml version=1.0?
 ?quicktime type=application/x-qtskin?
 skin
 movie src=../../fonovisa.mov/
 contentregion src=../images/mask.gif/
 dragregion src=../images/drag.gif/
 /skin
 
 
 If I use PHP to generate the same output, I get the error: can not
 modify the headers.
 Could the file extension, .php, somehow be preventing the php script
 from outputting properly ?

Do this:

od -c filename.php

And send us the output.  If it is really long, put it online somewhere.
 You have a stray carriage return or some other weird character in there
somewhere.

-Rasmus

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



Re: [PHP] Problems with headers

2005-09-22 Thread Rasmus Lerdorf
Graham Anderson wrote:
 Ok, I think I figured it out .
 
 I had to convert my BBedit text editor file to plain text and then
 copy/paste that text directly into a new  server text file
 So, I guess my $100+ text editor is screwing up the file ?
 Is there some way to prevent this ?

Tell your editor to not send a BOM.  If it won't let you configure that,
throw it away.

-Rasmus

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



Re: [PHP] exec command fails in php, works in the command line

2005-09-21 Thread Rasmus Lerdorf
[EMAIL PROTECTED] wrote:
 You're telling me.  That's why I think php or apache kills it.

I didn't really follow this, but typically you can debug exec problems
from the command line by switching to the web server user id and running
the exact same command.

-Rasmus

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



Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Rasmus Lerdorf
Lester Caine wrote:
 This type of code is used in a few places, so I'd like a little help
 converting it to 'good code' under the new rules ;)
 
 Get the key from an array ( fails because key(array) )
 
 if( $pId == key( $this-getFunc() ) ) {
 
 In getFunc()
 
 return ( $this-getAssoc(select Id, Content from database...);
 
 Current fix is just to create the array and use that
 $keyarray = $this-getFunc();
 if( $pGroupId == key( $keyarray ) ) {
 
 This works fine, but is there a 'proper' way to do it now that what
 looked tidy originally fails with an error?

There is nothing wrong with that code.  key() and current() don't need
to take a reference and this has been fixed in CVS and will be in the
next release.  It was overlooked in the past because we didn't have any
sort of warning about discarded references.  We have also fixed things
such that discarded references in other circumstances such as:
array_pop, array_shift, end(), etc. will only throw an E_STRICT in PHP
5.x.  E_STRICT is the new super-pendantic warning level that is disabled
by default but can be turned on to help you track down potential sources
of errors such as doing:

  sort($this-getArray());

If you have forgotten to make the getArray() method return its array by
reference, then that sort call will do absolutely nothing and it can
often be really hard to find a bug like that.

-Rasmus

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



Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Rasmus Lerdorf
Michael Sims wrote:
 Jochem Maas wrote:
 
foo($a = 5);

by definition the expression is evaluated _before_ the function is
called - so the expression is not passed to the function, the result
of the expression is passed ... I was under the impression that the
the expression evaluates to a 'pointer' (I'm sure thats bad
terminology) to $a ... which can taken by reference by the function.

possibly I am completely misunderstanding what goes on here.
 
 
 When used as an expression, an assignment evaluates to whatever is on the 
 right side of the assignment operator, not the left.  Example:
 
 var_dump($a = 5);
 outputs
 int(5)
 
 var_dump($a = some string);
 outputs
 string(11) some string
 
 So, as far as foo() knows:
 
 foo($a = 5);
 and
 foo(5);
 
 are exactly the same...

The value passed is the same, but when passed as $a=5 then the value has
a symbol table entry associated with it whereas if you just pass in 5 it
doesn't.  That means that:

function foo($arg) { $arg =6; }

will work if you call: foo($a=5);
but you will get an error if you have: foo(5);

The above should be pretty straightforward and isn't new.  What was
always fuzzy was this slightly more involved example:

function foo($arg) { $arg =6; }
function bar() { return 5; }
foo(bar());

Here we are essentially passing 5 to foo() again, but it isn't a
constant, it is what is known as a temp_var internally in PHP.  Chances
are code like this is hiding a bug, because the temp_var is going to
drop out of scope and the change to it in foo() will be discarded.  This
was initially made to throw a fatal error in PHP 5.x, which was a
mistake on our part.  It now throws an E_STRICT instead because in some
cases this may not actually be a bug.  There are some cases where you
don't care about the discarded reference.  In PHP 4.3.x assigning
references to temp_vars could cause memory corruption which prompted the
fixes to 4.4 and the introduction of an E_NOTICE in certain cases.

-Rasmus

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



Re: [PHP] Wikimedia - php4

2005-09-20 Thread Rasmus Lerdorf
Vizion wrote:
 Notice: Only variable references should be returned by reference 
 in /usr2/virtualwebs/forumkatrina.org/wiki/includes/ObjectCache.php on line 
 369
 
 Notice: Only variable references should be returned by reference 
 in /usr2/virtualwebs/forumkatrina.org/wiki/includes/ObjectCache.php on line 
 369
 
 Line 369 indicated by  ^^^
 -
 function _unserialize( $serial ) {
   if( function_exists( 'gzinflate' ) ) {
   $decomp = @gzinflate( $serial );
   if( false !== $decomp ) {
   $serial = $decomp;
   }
   }
   return unserialize( $serial );
 ^^
   }

A pretty standard case of someone not really understanding references in
PHP.  There is no need for this function to return a reference.  They
are likely doing it to try to avoid a copy, but no copy will be made in
the standard return by value case.  Simply remove the  from the
function definition to get rid of this notice.


 ---
 ***
 SECOND error -- Error line 136 indicated by ^
 ***
 Notice: Only variable references should be returned by reference 
 in /usr2/virtualwebs/forumkatrina.org/wiki/includes/SkinTemplate.php on line 
 136
 
   function decr($key, $value=1) {
   if ( !$this-lock($key) ) {
   return false;
   }
   $value = intval($value);
   if($value  0) $value = 0;
 
   $m = false;
 ^^^
   if( ($n = $this-get($key)) !== false ) {
   $m = $n - $value;
   if($m  0) $m = 0;
   $this-set($key, $m); // exptime?
   }
   $this-unlock($key);
   return $m;
   }

Are you sure you have the right code snippet here?  That's not a return
line and I see no references there.

-Rasmus

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



Re: [PHP] Wikimedia - php4

2005-09-20 Thread Rasmus Lerdorf
Vizion wrote:
   function setupTemplate( $classname, $repository=false, 
 $cache_dir=false ) {
   return new $classname();
 ^^
   }

Is that really all they have in that function?  It seems rather useless
to me.  Why call a function just to instantiate a class like that?

Regardless, here it is trying to create a reference to a temp var.
Basically PHP will ignore the reference here, and it should work, but
you are getting a notice because the reference is being discarded.
Either drop the reference from the function definition or do:

 $class = new $classname();
 return $class;

And for PHP5 you can just drop all references related to objects and it
will do the right thing.

-Rasmus

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



Re: [PHP] Wikimedia - php4

2005-09-20 Thread Rasmus Lerdorf
Robert Cummings wrote:
 On Wed, 2005-09-21 at 00:58, Rasmus Lerdorf wrote:
 
And for PHP5 you can just drop all references related to objects and it
will do the right thing.
 
 
 Eeeek, that's not entirely true. Sometimes you want a real reference to
 an object even in PHP5 :/

$a = new foo();

Will create a reference to the object.

$b = $a;

Now you have 2 references to the same object.

For any sort of normal use, you never need to explicitly create
references to objects in PHP 5.

-Rasmus

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



Re: [PHP] Wikimedia - php4

2005-09-20 Thread Rasmus Lerdorf
Robert Cummings wrote:
 I think you mean novice use. There are certainly times when assigning an
 object to a variable I want all the values currently referring to that
 object to see the update and not just the variable being assigned to. I
 understand that objects in PHP5 are passed by reference under normal
 assignment, but it's a copy of a reference and not a reference to a
 reference.

I am not sure I would call it novice use.  Normally you simply want to
manipulate the object itself.  As in:

class foo {
public $prop = 1;
}
$a = new foo();
$b = $a;
$b-prop++;
echo $a-prop;

This will of course output 2.  Manipulating the object through any of
its references will be reflected in all the others as there is just one
object here.

-Rasmus

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



Re: [PHP] Quick Poll: PHP 4 / 5

2005-09-16 Thread Rasmus Lerdorf
Stephen Leaf wrote:

 $this-urlArr[0] = array_pop($arr = explode(,$this-urlArr[0]));
 
 I still have to scratch my head as to why I *need* that $arr = 
 prior to 5.0.5 this was not needed.
 $this-urlArr[0] = array_pop(explode(,$this-urlArr[0]));

This is a much misunderstood issue.  And we are still contemplating the
best way to handle this.  Let's take a step back to a really simple example:

  function foo() {
return 3;
  }
  function bar($arg) {
$arg = banana;
  }
  bar(foo());

What do we do with code like this?  If you follow it through it is
essentially doing:

  3 = banana;

which makes very little sense and is probably something the developer
would want to know about.  PHP 4.3.x happily let you do this, and in
some circumstances this could even corrupt memory.  PHP 4.4 and higher
have fixed this memory corruption problem, and at the same time since we
are now able to detect this we can throw an error to let you know that
your code is probably not doing what you intended.

Now, in your example you are doing:

  $a = array_pop(explode(,ab));

to get the last element from the explode.  The issue with array_pop()
and other similar functions is that they do 2 things.  They modify the
array (by removing the last element) and they return something (the
removed element in this case).  When you pass in the result of explode()
you are passing in something that doesn't have any permanent storage
associated with it.  Internally in PHP this is known as a temp var.  You
can't make a reference to a temp var.  In our simpler example it is like
trying to do 3 which doesn't make any sense.  So in this case
array_pop() has no place to store the modification.  Your code happens
to not care about that and only cares about the returned value.

The real question here is whether we should silently ignore cases where
such an argument modification is thrown away.  In the case of
array_pop() it may make sense.  But how about this:

  sort(explode(,ab));

sort() has just one purpose.  That is to sort the passed array in place.
 The above line of code is a really slow line of code that does
absolutely nothing because we are passing in something that goes out of
scope as soon as the call is done.  This line of code in a PHP program
is an obvious bug.  Now, if we change this to:

  sort($a=explode(,ab));

then it suddenly makes sense.  This is equivalent to writing:

  $a = explode(,ab));
  sort($a);

and the result is that we have a sorted array in $a after this.

So the idea here is that PHP should be able to detect these sorts of
obvious errors.  In the array_pop() case it is not as black and white as
the sort() case because of the dual-purpose nature of array_pop().  You
could make a case for silently ignoring the array modification in
array_pop().

My personal feeling on this is that we should throw an E_NOTICE on these
and let the code continue on.  Often there is a more efficient way to do
some of these things simply because you are calling something that does
more than you need and ignoring some of what the function does and other
times, like with the sort() example, this is actually a real bug in your
code.

If it wasn't for the memory corruption associated with this, we wouldn't
have touched it in PHP 4 at all.  But since it caused weird and
wonderful crashes in complex PHP 4 code we didn't really have the option
to ignore it.  So what we do now is to demote impossible references to
non-references and throw an E_NOTICE.  In PHP 5 this ended up being a
fatal error which is something we have been discussing over the past
week.  In its current state having this as a fatal error is incorrect
and something we will fix.  We need to either make it an E_NOTICE or
there has been talk about coming up with a smarter way of handling these
impossible reference cases, but it is pretty tricky.

We don't always get things right on the first try.  Expect to see some
tweaks to the current implementation to make it more compatible with
existing code over the next couple of weeks.

-Rasmus

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



Re: [PHP] Quick Poll: PHP 4 / 5

2005-09-16 Thread Rasmus Lerdorf
Robert Cummings wrote:
 On Fri, 2005-09-16 at 10:28, Rasmus Lerdorf wrote:
 
Stephen Leaf wrote:

$this-urlArr[0] = array_pop($arr = explode(,$this-urlArr[0]));

I still have to scratch my head as to why I *need* that $arr = 
prior to 5.0.5 this was not needed.
$this-urlArr[0] = array_pop(explode(,$this-urlArr[0]));

This is a much misunderstood issue.  And we are still contemplating the
best way to handle this.  Let's take a step back to a really simple example:

  function foo() {
return 3;
  }
  function bar($arg) {
$arg = banana;
  }
  bar(foo());

What do we do with code like this?  If you follow it through it is
essentially doing:

  3 = banana;

which makes very little sense and is probably something the developer
would want to know about.
 
 
 I think this is part of the problem. While I understand how you got
 
 3 = banana
 
 I don't agree with your position that the above code is incorrect,
 rather I think there is a philosophical difference between some
 developers as to what should be expected. Most programmers (I would
 argue :), including myself say, Foo returns 3, the return value is
 stored in a temporary container, the temporary container is then fed
 into bar() which just happens to want a reference, so fine, it gets a
 reference to a temporary container, then it sets the value to banana.
 So finally we get back out to the bar(foo()) calling scope and we
 receive the temporary container. In which case the way people are using
 these functions and references are perfectly valid and passing temporary
 return containers to reference expecting functions is not necessarily a
 bug, but a philosophical question of understanding what the hell you're
 doing :) 

Well, this is the sort of thing the language should help you with.
Whether or not the code is incorrect or not is not the relevant question
I think.  The question is whether the language should try to detect when
you are doing something that is not going to do what you expect.  If
someone really writes code like the above, I see it as a plus if they
could get an optional warning about it.  That's exactly what an E_NOTICE
on this is for.

 As you are seeing now, we now have a horrible situation where
 the developer now has to care about whether they are passing a value to
 a function expecting a reference or not, and if that function expects a
 reference they now have to manually create a temporary container
 themselves :/ Anyways, I've already accepted whatever comes out of all
 this, but personally I don't think the code you showed above is wrong at
 all :)

Well, you can turn off notices, or rather not turn them on since they
are off by default, and you won't have to care.  Like I said, the
current fatal error in 5.0.5 on this is incorrect and we will fix that,
but I still believe it is a good idea to provide users with a way to get
warnings on cases where references are dropped since it could very well
hide a bug in their code.

-Rasmus

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



[PHP] Re: 302 Responses (Was: session cookies)

2005-09-06 Thread Rasmus Lerdorf
Chris Shiflett wrote:
 3. Chris's modified test script:
 
 header('Location: http://www.php.net/');
 $fp = fopen('/tmp/log.txt', 'w');
 for ($i = 0; $i  30; $i++)
 {
 $str = Count $i\n;
 echo str_repeat($str, 1000);
 fputs($fp, $str);
 sleep(1);
 flush();
 }

This redirects right away for me.  Try it:

http://lerdorf.com/cs.php

Code at: http://lerdorf.com/cs.phps

No idea what you are doing on your end to get a different result.

-Rasmus

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



[PHP] Re: 302 Responses (Was: session cookies)

2005-09-06 Thread Rasmus Lerdorf
Chris Shiflett wrote:
 Rasmus Lerdorf wrote:
 
 This redirects right away for me. Try it:

 http://lerdorf.com/cs.php

 Code at: http://lerdorf.com/cs.phps
 
 
 Thanks, that works. :-)
 
 For reference, here's mine (temporary URL, of course):
 
 http://shiflett.org/cs.php
 http://shiflett.org/cs.phps
 
 It's the same code, but it behaves differently. I don't have time to
 compare the responses, but I will later. My first instinct is that my
 server is buffering the response, but that was the first thing I checked
 when I was testing this locally.

Are you using mod_gzip perhaps?

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



Re: [PHP] Re: apache (root) + php4

2005-09-03 Thread Rasmus Lerdorf
Michelle Konzack wrote:
 Hi Rory,
 
 Am 2005-09-03 17:04:19, schrieb Rory Browne:
 
 
I'm not totally sure on the format of the passwords in /etc/shadow,
but can you do anything with php's md5 function? If not, then perhaps
the mcrypt extension may do something for you.
 
 
 Unfortunatly not, because
 
 echo -n michellesecret |md5sum
 or
 md5(michellesecret) 
 
 produce:28c2f05403caaa750df55efadeebd9ed
 
 but in /etc/shadow you find:$1$.NV7oLhO$Gj/ztvspUcpcJ5iUJiXNo0
 
 
 I do not find the right syntax and options to produce the later string.

The $1$.NV7oLhO$ is the SALT used by crypt.  But to make it easier,
php's crypt() function is smart enough to just take the correct part of
the string and treat it as the salt, so you can pass the whole thing in.
That is, when trying to match up a password, you can do this:

?php
$match = '$1$.NV7oLhO$Gj/ztvspUcpcJ5iUJiXNo0';
$passwd = 'michellesecret';

if(crypt($passwd,$match)==$match) echo It matched;
else It didn't match;
?

I think you will find that if you echo out the result of
crypt($passwd,$match) in the above, you will see:
$1$.NV7oLhO$Gj/ztvspUcpcJ5iUJiXNo0

-Rasmus

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



Re: [PHP] Re: php 5 upgrade - undefined index errors EVERYWHERE

2005-09-03 Thread Rasmus Lerdorf
Michelle Konzack wrote:
 Hello Jason,
 
 Am 2005-09-03 10:42:27, schrieb Jason Boerner:
 
My server was upgraded to php 5 and now nothing runs because of undefined
index errors all over the place..  How can I save myself from recoding for
hours and hours ??
 
 
 I have tried tu upgrade my Server to php5 too.
 Same Errors... several 1000...
 
 I am talking about 6 MByte PHP Scripts all over the Server.
 
 
Thank you in advance for any help you can offer.
 
 
 Unfortunatly not.  I have reinstalled php4.  Gmpf!

These are not errors, they are notices.  It happens on code like this:

?php
error_reporting(E_ALL);
$a = array();
echo $a['hello'];
?

You get an error like:

Notice: Undefined index:  hello in /var/home/rasmus/ty on line 4

It is meant to be helpful since you probably want to fix your code.  But
if you don't care about these, simply ignore the notices.

In your php.ini file, set your error_reporting level:

error_reporting  =  E_ALL  ~E_NOTICE  ~E_STRICT

-Rasmus

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



Re: [PHP] How to get GD to handle different image formats?

2005-09-03 Thread Rasmus Lerdorf
Graham Anderson wrote:
 I would like the gd library to handle the vector image format, PCT.
 
 GD is installed on my shared server and, unfortunately,  ImageMagick is
 not :(
 ImageMagick CAN export PCT files.
 
 Can I get GD to do this too ?

Not as far as I know, no.

-Rasmus

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



Re: [PHP] FreeBSD php{4,5} w/ LDAP + SSL/TLS ldap_start_tls()

2005-09-03 Thread Rasmus Lerdorf
(ldap_start_tls)
 {
zval **link;
ldap_linkdata *ld;
int rc, protocol = LDAP_VERSION3;

if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, link) ==
 FAILURE) {
WRONG_PARAM_COUNT;
}

ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, link, -1, ldap link,
 le_link);

if (((rc = ldap_set_option(ld-link, LDAP_OPT_PROTOCOL_VERSION,
 protocol)) != LDAP_SUCCESS) ||
((rc = ldap_start_tls_s(ld-link, NULL, NULL)) !=
 LDAP_SUCCESS)
) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,Unable to
 start TLS: %s, ldap_err2string(rc));
RETURN_FALSE;
} else {
RETURN_TRUE;
}
 }
 /* }}} */
 #endif



 On Fri, 2 Sep 2005, Rasmus Lerdorf wrote:

 Brian A. Seklecki wrote:

 Firstly, sorry if this is the wrong list.  There are thousands of
 forums
 and PHP5 related MLs, but nothing FBSD specific.

 Second, I wouldn't post if this wasn't happening on two completely
 different FBSD boxes.

 For whatever reason, the php4 and php5 from FreeBSD ports refuses to
 properly configure SSL/TLS support for the LDAP module.


 Can't you just build from the PHP tarball instead?  Seems like a messed
 up port to me.  I use FreeBSD all day, every day and haven't seen this
 problem.  But I also don't use the ports.

 -Rasmus


 l8*
 -lava

 x.25 - minix - bitnet - plan9 - 110 bps - ASR 33 - base8

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


 
 l8*
 -lava
 
 x.25 - minix - bitnet - plan9 - 110 bps - ASR 33 - base8

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



Re: [PHP] Generating images on the fly, linking via symlink?

2005-09-03 Thread Rasmus Lerdorf
Dan Trainor wrote:
 Dan Trainor wrote:
 
 Hello, all -

 This is a question that could depend on a completely different (yet,
 relayed) subject, so I'm sending this email to both php-general@ and
 [EMAIL PROTECTED]  I thank you in advance for your understanding.

 I am currently generating some images on the fly using some of PHP's
 image generation and rendering functions.  I'm having loads of
 success, and like the results that I see.

 What I'd like this script to do is, to create symlinks to the
 origional image, and then when the script is done running, the
 symlinks are deleted.  Basically trying to make it so that the
 origional image is not known to the client or browser.

 So I'm taking, say, image1.jpg.  I'm creating a symlink via:

 $linkname = md5(rand());

 or something similar.  I'd then like to return $linkname to the client
 or browser.  Then, when the browser has completed rendering the page
 to the client or browser, the symlink is then deleted.

 What I'm curious as to right now is if I do this, the client will see
 the link to $linkname via HTML's img src= specification.  What
 happens if this is sent to the client or browser, and the symlink is
 deleted immediately after the name is sent to the client or browser? 
 Would the web server (in this case, Apache) cache the image in memory
 until the client has downloaded said image, and then delete it from
 memory when the page is done rendering or being sent?  Will PHP
 totally disregard the web server's request to hold the image, and
 render nothing to the browser?  This is something I'm confused about.

 Thanks!
 -dant

 
 Hello -
 
 Don't suppose anyone has any pointers for me with this one, do ya?

I don't quite see how you know when the browser has fetched the image.
Browsers make requests for images in a separate connection, so on the
page where you generate this random symlink you are just adding an img
src=... / tag which will prompt the remote browser to at some point
open a separate connection and ask for that image.

I think a better idea may be to forget about symlinks and just keep a
local mapping table of random ids to images and in your page have
something like:

  img src=/view/123456789.jpg /

Then make /view a PHP script.  In your Apache config you can do that by
adding:

  Location /view
  ForceType application/x-httpd-php
  /Location

And in your /view script look at $_SERVER['PATH_INFO'] which should be
/123456789.jpg.  Pick out the image id, look up in your local lookup
table which actual image that refers to and serve it up with a
readfile() call.  Remember to set the the appropriate
header('Content-type: image/jpeg) at the top.

You can also do a similar thing by using an ErrorDocument 404 /view.php
but the big downside of this is that Apache will log a 404 error on
every image view.

You do take a bit of a hit by going through php to serve up the image as
opposed to using your symlink approach where the actual request will go
directly via Apache's path_translate hook to the image you want.  The
problem is that without any PHP involvement on the actual image request
you don't any way of knowing when the request has come in for the image
and thus you have no way to know when to delete the symlink.  You could
of course set up a cron job that goes through and deletes all symlinks
older than 5 minutes or something like that, but that may not meet your
requirements.

-Rasmus

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



Re: [PHP] session cookies

2005-09-02 Thread Rasmus Lerdorf
Chris Shiflett wrote:
 Rasmus Lerdorf wrote:
 
 That's a bit misleading. The HTTP response headers are sent a soon
 as you output something from your script (calling header() or
 setcookie() doesn't count as output, so you can set all the headers
 and cookies you want).
 
 
 They're sent to Apache, but that doesn't mean anything is necessarily
 sent to the client, right? I guess I should have pointed out that this
 depends on a few things, such as whether the response is sent with:
 
 Transfer-Encoding: chunked
 
 or
 
 Content-Length: ...
 
 Common sense tells me that Apache can't provide a reliable
 Content-Length header until my script completes. :-)

Which is why dynamic requests typically do not have a content-length
header.  Unless you explicitly turn on output buffering, the headers are
sent as soon as you send your first real output.  The end of the request
has nothing to do with it.

  And the browsers tend to redirect right away once they get this
 header.
 
 I would find that very surprising. Maybe I'll experiment. If I
 understand you correctly, you're suggesting that a browser will request
 the new URL before receiving the previous response in its entirety. Even
 assuming a chunked transfer encoding, that seems weird.

Consider yourself surprised then, that is how things work.

-Rasmus

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



Re: [PHP] session cookies

2005-09-02 Thread Rasmus Lerdorf
Chris Shiflett wrote:
 Chris Shiflett wrote:
 
  And the browsers tend to redirect right away once they get this
  header.

 I would find that very surprising. Maybe I'll experiment.
 
 
 I tested this with Firefox 1.0.4, Firefox 1.0.6, and Safari 1.3. None of
 them request the new URL before receiving the previous response in its
 entirety. Maybe Internet Explorer does. :-)

Then you have configured your server to always turn on output buffering
or your test script is bad.

Try this:

?php
header(Location: http://www.php.net;);
$fp = fopen(/tmp/log.txt,w);
for($i=0; $i100; $i++) {
$str = Count $i\n;
echo $str;
fputs($fp, $str);
}
?

What do you think you will see both on your screen and in /tmp/log.txt?

-Rasmus

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



  1   2   3   4   5   6   7   8   9   10   >