OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
php-general Digest 7 Jul 2005 01:11:21 -0000 Issue 3553

php-general-digest-helplists.php.net
Date: Wed Jul 06 2005 - 20:11:21 CDT


php-general Digest 7 Jul 2005 01:11:21 -0000 Issue 3553

Topics (messages 218198 through 218272):

Re: IBM's Learning PHP Part 1 tutorial.
        218198 by: Andr Medeiros
        218199 by: Jay Blanchard
        218200 by: Richard Davey
        218201 by: John Nichel
        218202 by: Andr Medeiros
        218203 by: Richard Davey
        218205 by: Angelo Zanetti
        218206 by: Marek Kilimajer
        218216 by: chris
        218220 by: Richard Davey
        218228 by: William James McEachran
        218241 by: Richard Lynch
        218258 by: Richard Davey
        218263 by: Richard Lynch
        218266 by: Richard Davey

hi
        218204 by: Automatic Email Delivery Software
        218213 by: Automatic Email Delivery Software

Re: Support for Oracle 10g in php 5.0.4
        218207 by: Catalin Trifu

recompiling php
        218208 by: blackwater dev
        218209 by: John Nichel
        218214 by: Brian V Bonini
        218236 by: blackwater dev

Re: Find largest integer filename
        218210 by: Philip Hallstrom
        218215 by: Matt Blasinski

Jmbbvfxiuwuzy
        218211 by: Automatic Email Delivery Software

Re: alternative to empty
        218212 by: Philip Hallstrom

Loops inside of a loop
        218217 by: Moises Zaragoza
        218219 by: Jay Blanchard
        218242 by: Richard Lynch

DELIVERY FAILED
        218218 by: Automatic Email Delivery Software

RH 9: Installing PHP 4.3
        218221 by: Todd Cary
        218237 by: Richard Lynch

date() problem
        218222 by: Ryan A
        218227 by: Edward Vermillion
        218230 by: Edward Vermillion
        218235 by: Richard Lynch
        218244 by: Kristen G. Thorson
        218245 by: Edward Vermillion
        218248 by: Philip Hallstrom
        218254 by: Edward Vermillion
        218255 by: Edward Vermillion

XML and PHP
        218223 by: Cima
        218224 by: Jay Blanchard
        218226 by: Charles Stuart

Re: foreach in php4
        218225 by: Dotan Cohen

pear channel
        218229 by: blackwater dev
        218231 by: Matthew Weier O'Phinney

Use of + with arrays
        218232 by: Bob Stearns
        218234 by: Richard Lynch

Help - need to quickly optimize a record count!
        218233 by: Brian Dunning
        218238 by: Matthew Weier O'Phinney
        218239 by: Brian Dunning
        218240 by: SGreen.unimin.com
        218249 by: Peter
        218269 by: Richard Lynch
        218271 by: Brian Dunning

report
        218243 by: Mail Delivery Subsystem
        218256 by: Richard Lynch

Re: PHP 5.1 vm
        218246 by: Richard Lynch
        218250 by: Richard Lynch
        218252 by: Robert Cummings
        218264 by: Richard Lynch
        218265 by: Dan Rossi
        218267 by: Robert Cummings

Re: xmdom clone(true) & CDATA + html(?) encoding
        218247 by: Richard Lynch

Re: Building sapi_apache2
        218251 by: Richard Lynch

Re: who can do this without the recursion
        218253 by: Richard Lynch

trouble with file upload page using PHP
        218257 by: Bruce Gilbert
        218259 by: Richard Davey

iCalendar creation not working with Outlook
        218260 by: Daevid Vincent
        218261 by: Rasmus Lerdorf
        218262 by: Richard Lynch
        218270 by: Daevid Vincent

help, no jpeg support compiled in
        218268 by: Christopher J. Bottaro
        218272 by: Richard Lynch

Administrivia:

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

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

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

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

attached mail follows:


On Tue, 2005-07-05 at 22:36 -0400, Bill McEachran wrote:
> Newbie question.
>
> I'm working my way through IBM's PHP tutorial. Generally good ... but
> I'm stuck at an error point and have no idea what's going wrong.
> Before adding a new row to the mysql database (already opened) we do a
> query to see if a particular record already exists.
> (see $resultT).
>
> We then test, using if, to see if $resultT is true or false. If it's
> false we are then supposed to enter a new record.
> Problem: it's never false. It always evaluates true. What am I doing
> wrong? TIA
>
> /* build query to see if the record is entered already */
> $sqlT = "select * from users where username='".$_POST["name"]."'";
> $resultT = mysql_query($sqlT);
>
> /* Now test -- did we find anything ... if not add this user */
> if (! $resultT) {
> /* here we add the new record if it doesn't already exit /*
>

Although I'm not sure that will work, mysql_num_rows( $resultT ) == 1
will tell you for sure if the user exists or not.

Just remember to addslashes() to $_POST['name'] before doing that query,
so SQL can't be injected.

attached mail follows:


[snip]
We then test, using if, to see if $resultT is true or false. If it's
false we are then supposed to enter a new record.
Problem: it's never false. It always evaluates true. What am I doing
wrong? TIA

/* build query to see if the record is entered already */
     $sqlT = "select * from users where username='".$_POST["name"]."'";
     $resultT = mysql_query($sqlT);

/* Now test -- did we find anything ... if not add this user */
     if (! $resultT) {
/* here we add the new record if it doesn't already exit /*
[/snip]

You have set $resulT like this;

$resultT = mysql_query($sqlT);

So it will always be true. What you want to do now is find if $resultT
contains any rows;

if(0 != mysql_num_rows($resultT)){
        /* add record */
} else {
        echo "Record already exists\n";
}

attached mail follows:


Hello Bill,

Wednesday, July 6, 2005, 3:36:09 AM, you wrote:

BM> I'm working my way through IBM's PHP tutorial. Generally good ...
BM> but I'm stuck at an error point and have no idea what's going
BM> wrong. Before adding a new row to the mysql database (already
BM> opened) we do a query to see if a particular record already
BM> exists. (see $resultT).

BM> We then test, using if, to see if $resultT is true or false. If
BM> it's false we are then supposed to enter a new record. Problem:
BM> it's never false. It always evaluates true. What am I doing wrong?

BM> /* build query to see if the record is entered already */
BM> $sqlT = "select * from users where
BM> username='".$_POST["name"]."'";
BM> $resultT = mysql_query($sqlT);

BM> /* Now test -- did we find anything ... if not add this user */
BM> if (! $resultT) {
BM> /* here we add the new record if it doesn't already exit /*

To be honest that is quite shocking code, especially from a "teaching
beginners" perspective - and even more so coming from the likes of
IBM. But, SQL injection issues aside, the problem is most likely that
there is nothing wrong with your SQL query. mysql_query will return a
false (for a SELECT query) only if there is an error, not if "no
records exist" - that isn't an error.

It would make more sense to actually do a: "SELECT COUNT(*) AS hits FROM
users WHERE username = 'x'" and then check the value of the returned
"hits" (which will always return something, even if zero).
Alternatively instead of doing if (!$result) you could do: if
(mysql_num_rows($result) > 0) ... that way you know that the user
already exists.

Best regards,

Richard Davey
--
 http://www.launchcode.co.uk - PHP Development Services
 "I do not fear computers. I fear the lack of them." - Isaac Asimov

attached mail follows:


Bill McEachran wrote:
> Newbie question.
>
> I'm working my way through IBM's PHP tutorial. Generally good ... but
> I'm stuck at an error point and have no idea what's going wrong.
> Before adding a new row to the mysql database (already opened) we do a
> query to see if a particular record already exists.
> (see $resultT).
>
> We then test, using if, to see if $resultT is true or false. If it's
> false we are then supposed to enter a new record.
> Problem: it's never false. It always evaluates true. What am I doing
> wrong? TIA
>
> /* build query to see if the record is entered already */
> $sqlT = "select * from users where username='".$_POST["name"]."'";
> $resultT = mysql_query($sqlT);

http://us2.php.net/mysql_query

mysql_query() will only return an error IF the query CANNOT be executed.
  Basically, your query is executing fine, it's just returning zero
results. Check to see if any rows were returned...

http://us2.php.net/mysql_num_rows

if ( ! mysql_num_rows ( $resulT ) ) {
        // No results returned
}

--
John C. Nichel
berGeek
KegWorks.com
716.856.9675
johnkegworks.com

attached mail follows:


On Wed, 2005-07-06 at 14:12 +0100, Richard Davey wrote:
> Hello Bill,
>
> Wednesday, July 6, 2005, 3:36:09 AM, you wrote:
>
> BM> I'm working my way through IBM's PHP tutorial. Generally good ...
> BM> but I'm stuck at an error point and have no idea what's going
> BM> wrong. Before adding a new row to the mysql database (already
> BM> opened) we do a query to see if a particular record already
> BM> exists. (see $resultT).
>
> BM> We then test, using if, to see if $resultT is true or false. If
> BM> it's false we are then supposed to enter a new record. Problem:
> BM> it's never false. It always evaluates true. What am I doing wrong?
>
> BM> /* build query to see if the record is entered already */
> BM> $sqlT = "select * from users where
> BM> username='".$_POST["name"]."'";
> BM> $resultT = mysql_query($sqlT);
>
> BM> /* Now test -- did we find anything ... if not add this user */
> BM> if (! $resultT) {
> BM> /* here we add the new record if it doesn't already exit /*
>
> To be honest that is quite shocking code, especially from a "teaching
> beginners" perspective - and even more so coming from the likes of
> IBM. But, SQL injection issues aside, the problem is most likely that
> there is nothing wrong with your SQL query. mysql_query will return a
> false (for a SELECT query) only if there is an error, not if "no
> records exist" - that isn't an error.
>
> It would make more sense to actually do a: "SELECT COUNT(*) AS hits FROM
> users WHERE username = 'x'" and then check the value of the returned
> "hits" (which will always return something, even if zero).
> Alternatively instead of doing if (!$result) you could do: if
> (mysql_num_rows($result) > 0) ... that way you know that the user
> already exists.
>
> Best regards,
>
> Richard Davey
> --
> http://www.launchcode.co.uk - PHP Development Services
> "I do not fear computers. I fear the lack of them." - Isaac Asimov
>

Depending on the sittuation, IMHO, COUNT(*) wouldn't be the way to go.
If you need the user's id or somesuch, you have to run an additional
query to get the info.

mysql_num_rows($result) will do just fine.

attached mail follows:


Hello Andr,

Wednesday, July 6, 2005, 3:25:37 PM, you wrote:

AM> Depending on the sittuation, IMHO, COUNT(*) wouldn't be the way to
AM> go. If you need the user's id or somesuch, you have to run an
AM> additional query to get the info.

But they're returning absolutely nothing in this case - which
(providing username was indexed) would make count() a far quicker and
less expensive query than selecting and bring back data and then doing
absolutely nothing with it (somewhat pointless imho)

Best regards,

Richard Davey
--
 http://www.launchcode.co.uk - PHP Development Services
 "I do not fear computers. I fear the lack of them." - Isaac Asimov

attached mail follows:


have to agree with Richard here, its wasting resources bringing back *
from the database. Its one of those fundamentals. Only do a select *
from... where you actually need all the info.

Bill, try read the manual to see how the |mysql_query() returns info.
SOmeone has posted the link in this thread!
|

Richard Davey wrote:

>Hello Andr,
>
>Wednesday, July 6, 2005, 3:25:37 PM, you wrote:
>
>AM> Depending on the sittuation, IMHO, COUNT(*) wouldn't be the way to
>AM> go. If you need the user's id or somesuch, you have to run an
>AM> additional query to get the info.
>
>But they're returning absolutely nothing in this case - which
>(providing username was indexed) would make count() a far quicker and
>less expensive query than selecting and bring back data and then doing
>absolutely nothing with it (somewhat pointless imho)
>
>Best regards,
>
>Richard Davey
>
>

attached mail follows:


Richard Davey wrote:
> Hello Andr,
>
> Wednesday, July 6, 2005, 3:25:37 PM, you wrote:
>
> AM> Depending on the sittuation, IMHO, COUNT(*) wouldn't be the way to
> AM> go. If you need the user's id or somesuch, you have to run an
> AM> additional query to get the info.
>
> But they're returning absolutely nothing in this case - which
> (providing username was indexed) would make count() a far quicker and
> less expensive query than selecting and bring back data and then doing
> absolutely nothing with it (somewhat pointless imho)

You can select just the id, and provided that the query returns just
zero or one row, you can spare one function call.

attached mail follows:


Bill I like doing a switch statement base on the returned count from the
query. I feel this gives me better control over the output. keep in mind
that you can not use mysql_num_rows() with anything but a select statement.
also you would turn off error reporting in the ini file since this is a
system to replace that.
example
$query = "select userLvl from users where userName='".$_POST['userName']."'"
$result = mysql_query($query,$conn);
$ttlReturned = mysql_num_row($result);
switch($ttlReturned)
{
   case -1:
       // db error. process this and fail gracefully
       break;
   case 0:
       // no results returned. enter the new user
       break;
   case 1:
       // one record found. return a notice to the user the name exist
       break;
   default:
       // this would be a catch all for more than one record found. This may
record a // message to be sent to the db admin to correct, if you
only want one user // with this name.
}
// continue script with result from above.....

Chris

"Bill McEachran" <billmcdataffinity.com> wrote in message
news:42CB4399.7030303dataffinity.com...
> Newbie question.
>
> I'm working my way through IBM's PHP tutorial. Generally good ... but I'm
> stuck at an error point and have no idea what's going wrong.
> Before adding a new row to the mysql database (already opened) we do a
> query to see if a particular record already exists.
> (see $resultT).
>
> We then test, using if, to see if $resultT is true or false. If it's
> false we are then supposed to enter a new record.
> Problem: it's never false. It always evaluates true. What am I doing
> wrong? TIA
>
> /* build query to see if the record is entered already */
> $sqlT = "select * from users where username='".$_POST["name"]."'";
> $resultT = mysql_query($sqlT);
>
> /* Now test -- did we find anything ... if not add this user */
> if (! $resultT) {
> /* here we add the new record if it doesn't already exit /*

attached mail follows:


Hello Marek,

Wednesday, July 6, 2005, 3:15:58 PM, you wrote:

MK> You can select just the id, and provided that the query returns just
MK> zero or one row, you can spare one function call.

Sure that will work fine - but I fail to see how it will save a
function call. You either select, check there was no mysql error and
then check numrows. Or you select count, check there was no mysql
error and check the count value. I fail to see how your method
provides on less function call, but please elaborate :) (and hey,
select count = less bytes transferred from MySQL to PHP, regardless ;)

Best regards,

Richard Davey
--
 http://www.launchcode.co.uk - PHP Development Services
 "I do not fear computers. I fear the lack of them." - Isaac Asimov

attached mail follows:


> > Newbie question.
> >
> > I'm working my way through IBM's PHP tutorial. Generally good ... but I'm
> > stuck at an error point and have no idea what's going wrong.
> > Before adding a new row to the mysql database (already opened) we do a
> > query to see if a particular record already exists.
> > (see $resultT).

Thanks to all who replied.
It's been a long time since I tackled learning something new-and-different
and the php-mysql combo is new-and-different to me.
I appreciate everyone whose made it a little easier for me.
--
Bill McEachran

attached mail follows:


On Wed, July 6, 2005 10:43 am, Richard Davey said:
> Hello Marek,
>
> Wednesday, July 6, 2005, 3:15:58 PM, you wrote:
>
> MK> You can select just the id, and provided that the query returns just
> MK> zero or one row, you can spare one function call.
>
> Sure that will work fine - but I fail to see how it will save a
> function call. You either select, check there was no mysql error and
> then check numrows. Or you select count, check there was no mysql
> error and check the count value. I fail to see how your method
> provides on less function call, but please elaborate :) (and hey,
> select count = less bytes transferred from MySQL to PHP, regardless ;)

[pedantic]
Actually, I think the "SELECT id" will transfer less data in the cases
where no rows are returned.

There are no rows to return, after all, whereas the count(*) will always
return exactly one row.

And in the case case where a row is returned, the id will probably be the
same number of bytes as a count(*): a 32-bit integer.

What's more, the num_rows is always available, so is PROBABLY pushed
through the MySQL/PHP pipe from the get-go. So count(*) has the 32-bits
for the number of rows, which is always 1, and 32-bits for the result,
which is either 1 or 0.

The "SELECT id" has the number of rows, which is 1 or 0, and either
32-bits more for the id, or nothing more, ignoring the overhead of a
returned row, which should be the same in either case.
[/pedantic]

MySQL's "select count(*) " are optimized, but I believe that does not
apply if you have a WHERE clause.

Presumably, your id field is indexed.

So it boils down to MySQL having to count the one (1) row returned, rather
than just return the row, if had to "find" anyway, PLUS sometimes shoving
4 bytes "extra" through the MySQL/PHP connection, when the count(*) is 0.

I really don't have any idea which of these is "faster", and I suspect
you'd have a hell of a time making any significant improvement to any
real-world application by choosing one over the other.

But I'm guessing that if you actually managed to measure it accurately,
"SELECT id" would be a gnat's whisker "faster" in cases where no rows were
returned, and barely perceptible "faster" when there is a row, since MySQL
doesn't have to "count()" the result set -- Which really means just
copying the num_rows it has already calculated, most likely, in place of
the actual result.

Do feel free to benchmark on your hardware under your load conditions to
find out, and use the one that saves you 0.00000001 seconds, if you've got
nothing better to work on. :-)

I'm not particularly interested in the answer, myself, as I'm confident
that neither method is going to make a perceptible difference in
performance at the level that a real user would notice. :-) :-) :-)

Disclaimer: I could be 100% wrong in my analysis of the internal workings
of software whose source I've never read.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


Hello Richard,

Wednesday, July 6, 2005, 10:18:05 PM, you wrote:

RL> Actually, I think the "SELECT id" will transfer less data in the
RL> cases where no rows are returned.

Yes, I would agree with that.

RL> There are no rows to return, after all, whereas the count(*) will
RL> always return exactly one row.

Yup.

RL> And in the case case where a row is returned, the id will probably
RL> be the same number of bytes as a count(*): a 32-bit integer.

Say you've got user number 20,000 in a table. He only exists once, so
count() only returns 1. Bring back the ID and you'll get sent a value
of 20000. I would be shocked if, on a byte for byte transfer level,
there was no difference between the two. Once it's in memory at the
other end, sure they'll both most likely become longs anyway.

As for the query itself, MySQL could use its query cache on either and
both would require the same analysis of the index/table to obtain
their end result due to the where clause.

RL> What's more, the num_rows is always available, so is PROBABLY
RL> pushed through the MySQL/PHP pipe from the get-go. So count(*) has
RL> the 32-bits for the number of rows, which is always 1, and 32-bits
RL> for the result, which is either 1 or 0.

Yes, the num_rows value will always be available, because of the
success of the select query. So yes, it is passed back and ultimately
stored in a long. Using count() has no effect here.

RL> But I'm guessing that if you actually managed to measure it
RL> accurately, "SELECT id" would be a gnat's whisker "faster" in
RL> cases where no rows were returned, and barely perceptible "faster"
RL> when there is a row, since MySQL doesn't have to "count()" the
RL> result set -- Which really means just copying the num_rows it has
RL> already calculated, most likely, in place of the actual result.

From MySQLs point of view num_rows is calculated and returned to PHP
irrespective of which method you use.

You could mysql_num_rows it and then PHP will have to perform a zend
fetch resource, doing an index look-up on the hash (and returning the
result). Or if you've count'ed it, it'll have to return the value
stored via a mysql_result call (or similar), which takes a few more
trips around the hash table.

When it comes down to milliseconds, I doubt there is much in it to be
honest. Certainly something hard (and I'm sure you'd agree useless) to
quantify. But hey, we're being pedantic here, yes? :) At the end of
the day it just seems like a coding preference to me. After all, I
don't want the users ID number, I want to know how many users exist
matching that username (i.e. I want a count of them), so that's what
I've directly asked MySQL for.

A "one cat, 1 billion skinning combinations" scenario again I feel.

Best regards,

Richard Davey
--
 http://www.launchcode.co.uk - PHP Development Services
 "I do not fear computers. I fear the lack of them." - Isaac Asimov

attached mail follows:


On Wed, July 6, 2005 4:21 pm, Richard Davey said:
> RL> And in the case case where a row is returned, the id will probably
> RL> be the same number of bytes as a count(*): a 32-bit integer.
>
> Say you've got user number 20,000 in a table. He only exists once, so
> count() only returns 1. Bring back the ID and you'll get sent a value
> of 20000. I would be shocked if, on a byte for byte transfer level,
> there was no difference between the two. Once it's in memory at the
> other end, sure they'll both most likely become longs anyway.

You've just made my point.

The actual data tuple returned in both cases is a long, if there is a user
to match.

But the data returned, for SELECT id, when NO rows are there is, well,
nothing. Not even a long. For count(*) there is an "extra" long being
returned, in the tuple, that is already available in num_rows() anyway.

> When it comes down to milliseconds, I doubt there is much in it to be
> honest. Certainly something hard (and I'm sure you'd agree useless) to
> quantify. But hey, we're being pedantic here, yes? :) At the end of
> the day it just seems like a coding preference to me. After all, I
> don't want the users ID number, I want to know how many users exist
> matching that username (i.e. I want a count of them), so that's what
> I've directly asked MySQL for.

99 times out of a hundred, the very next thing your application is gonna
do is get their ID, maybe their name, maybe their email, etc, so you can
do something more interesting in your script than just know they exist.

Better to plan out your application and figure out what data you need on
most every page, and write one query to get that data, than to have the
un-coordinated mass of queries to all hit the same table, the same index,
and the same user data.

I can't count how many times I see junk like:

$db = new dbi_thingie_the_programmer_clearly_doesnt_understand();
$id = $db->get_id();
$name = $db->get_name($id);
$address = $db->get_address($id);
.
.
.

Bam! 10 hits to the database on every damn page.

Ugh.

Only the fact that PHP and MySQL are so blazing fast allows this kind of
Bad Coding to exist.

Some days I think newbies should be forced to use IBM PC Jrs with 16K RAM
and a 60 Meg hard drive (or whatever) just so they learn to code... :-)

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


Hello Richard,

Thursday, July 7, 2005, 1:16:29 AM, you wrote:

RL> You've just made my point.

RL> The actual data tuple returned in both cases is a long, if there
RL> is a user to match.

This is where we differ :) I don't believe MySQL will return an entire
longs worth of data (typically 4 bytes) if the value is simply 1. By
return I mean across the network, etc. But maybe that is blind faith
in the skills of MySQLs developers? ;)

RL> 99 times out of a hundred, the very next thing your application is
RL> gonna do is get their ID, maybe their name, maybe their email,
RL> etc, so you can do something more interesting in your script than
RL> just know they exist.

Sure. But in the example given this wasn't the use of the query - they
were checking to see if the user existed so they could INSERT a new
one.

RL> Some days I think newbies should be forced to use IBM PC Jrs with
RL> 16K RAM and a 60 Meg hard drive (or whatever) just so they learn
RL> to code... :-)

I dunno.. I've seen shit code on every single system I've ever come
across :)

Best regards,

Richard Davey
--
 http://www.launchcode.co.uk - PHP Development Services
 "I do not fear computers. I fear the lack of them." - Isaac Asimov

attached mail follows:


Your message was not delivered due to the following reason(s):

Your message could not be delivered because the destination computer was
unreachable within the allowed queue period. The amount of time
a message is queued before it is returned depends on local configura-
tion parameters.

Most likely there is a network problem that prevented delivery, but
it is also possible that the computer is turned off, or does not
have a mail system running right now.

Your message could not be delivered within 6 days:
Host 48.89.66.249 is not responding.

The following recipients did not receive this message:
<php-generallists.php.net>

Please reply to postmasterlists.php.net
if you feel this message to be in error.

attached mail follows:


Dear user php-generallists.php.net,

Your email account has been used to send a large amount of spam during the last week.
Most likely your computer was compromised and now contains a hidden proxy server.

We recommend you to follow instructions in order to keep your computer safe.

Best regards,
lists.php.net user support team.

attached mail follows:


       I have multiple installations of Oracle 10g -> two on linux and one on win32.
Apache is on linux and php is compiled with oci8 and without oracle. I connect with php
to all oracle servers without problems; one of them is on the same machine as the server.

Catalin

Chuck Carson wrote:
> I'm having problems getting php 5.0.4 working with Oracle 10.1.0.3 and
> just wanted to check and make sure 10g was supported before wasting
> any more cycles on it.
>
> Thx,
> CC

attached mail follows:


I have a linux box which I use periodically. I built php 5.0.3 on it
and it runs fine. I just came across a situation where I need to
compile in the zlib extension so I got into my php folder and did
./configure with my options, then make and make install. I then
restarted Apache but when I look at phpinfo, it still shows the old
command used to build php, not the command I just used to recompile.
Are there other things needed in a recompile?

Thanks!

attached mail follows:


blackwater dev wrote:
> I have a linux box which I use periodically. I built php 5.0.3 on it
> and it runs fine. I just came across a situation where I need to
> compile in the zlib extension so I got into my php folder and did
> ./configure with my options, then make and make install. I then
> restarted Apache but when I look at phpinfo, it still shows the old
> command used to build php, not the command I just used to recompile.
> Are there other things needed in a recompile?

Did you build it as a static module or DSO? ie.

--with-apache=../path/to/apache/source

or

--with-apxs=/path/to/apxs

--
John C. Nichel
berGeek
KegWorks.com
716.856.9675
johnkegworks.com

attached mail follows:


On Wed, 6 Jul 2005, blackwater dev wrote:

> I have a linux box which I use periodically. I built php 5.0.3 on it
> and it runs fine. I just came across a situation where I need to
> compile in the zlib extension so I got into my php folder and did
> ./configure with my options, then make and make install. I then
> restarted Apache but when I look at phpinfo, it still shows the old
> command used to build php, not the command I just used to recompile.
> Are there other things needed in a recompile?
>

Which distro are you running. Adding libs with Linux *CAN* be a simple as
'$ urpmi php-zlib' depending on which flavor your running.

attached mail follows:


I install it with this:
> --with-apxs=/path/to/apxs

So what is the order?

I cd'd into my php directory and did:
./configure with my options
make
make install

Then I went into my apache folder and did
./configure with options
make
make install

Then rebooted and started apache but when I look at phpinfo it still
shows the old command used to build it.

What am I missing?

On 7/6/05, John Nichel <johnkegworks.com> wrote:
> blackwater dev wrote:
> > I have a linux box which I use periodically. I built php 5.0.3 on it
> > and it runs fine. I just came across a situation where I need to
> > compile in the zlib extension so I got into my php folder and did
> > ./configure with my options, then make and make install. I then
> > restarted Apache but when I look at phpinfo, it still shows the old
> > command used to build php, not the command I just used to recompile.
> > Are there other things needed in a recompile?
>
> Did you build it as a static module or DSO? ie.
>
> --with-apache=../path/to/apache/source
>
> or
>
> --with-apxs=/path/to/apxs
>
> --
> John C. Nichel
> berGeek
> KegWorks.com
> 716.856.9675
> johnkegworks.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

attached mail follows:


> Suppose I have a directory with a HUGE number of filenames, all of which
> happen to look like integers:
>
> ~/nntp/1
> ~/nntp/2
> ~/nntp/3
> .
> .
> .
> ~/nntp/59874
> ~/nntp/59875
> ~/nntp/59876
>
> Now, in a PHP script, what's the most efficient way to find the "largest"
> filename, where "largest" means in the sense of an integer, not a string?
>
> I could probably force the filenames to be 0-padded if that would make a
> significant difference.
>
> Is there some nifty shell command I should just "exec"?...
>
> I don't really care which shell, but I'm a bash user generally.
>
> Obviously I could loop through all the filenames, so I'm looking for
> something faster than that. :-)

I can't think of anything you could do in the shell that would be
faster...

Anything you do in the shell is going to involve 'ls' which is going to
have to loop through all the filenames anyway... so you might as well do
it within PHP and save yourself the exec and other processes to sort/trim
the list.

I suppose you could try some sort of hunt and peck search... say you had
some idea how many files where in there (under say 10,000). Then you
could maybe do something like checking if 5000 exists. If it does, check
7500. If it doesn't, check 6250. If it does, check 6875 and so on until
you're down to a reasonable "gap". Then just check incrementally from
there.

Whether or not that's going to be faster than just looping through them
all I don't know...

good luck!

-philip

attached mail follows:


I can't believe I'm posting this :-p I'm nowhere near being a
unix/linux guru, and one would probably have a dozen complaints with
this if they saw it, but....

ls -l | grep -v total | cut -f 11 -d ' ' | sort -n | tail -1

Your milage may vary if ls -l displays something slightly different than
mine does, then try adjusting which field cut takes.

HTH,

Matt

Philip Hallstrom wrote:
>> Suppose I have a directory with a HUGE number of filenames, all of which
>> happen to look like integers:
>>
>> ~/nntp/1
>> ~/nntp/2
>> ~/nntp/3
>> .
>> .
>> .
>> ~/nntp/59874
>> ~/nntp/59875
>> ~/nntp/59876
>>
>> Now, in a PHP script, what's the most efficient way to find the "largest"
>> filename, where "largest" means in the sense of an integer, not a string?
>>
>> I could probably force the filenames to be 0-padded if that would make a
>> significant difference.
>>
>> Is there some nifty shell command I should just "exec"?...
>>
>> I don't really care which shell, but I'm a bash user generally.
>>
>> Obviously I could loop through all the filenames, so I'm looking for
>> something faster than that. :-)
>
>
> I can't think of anything you could do in the shell that would be faster...
>
> Anything you do in the shell is going to involve 'ls' which is going to
> have to loop through all the filenames anyway... so you might as well do
> it within PHP and save yourself the exec and other processes to
> sort/trim the list.
>
> I suppose you could try some sort of hunt and peck search... say you had
> some idea how many files where in there (under say 10,000). Then you
> could maybe do something like checking if 5000 exists. If it does,
> check 7500. If it doesn't, check 6250. If it does, check 6875 and so
> on until you're down to a reasonable "gap". Then just check
> incrementally from there.
>
> Whether or not that's going to be faster than just looping through them
> all I don't know...
>
> good luck!
>
> -philip
>

--
Matt Blasinski (mbv)
Information Systems Technology Services Professional
Internet Infrastructure Applications Technology
Division of Information Technology
3228 Computer Science and Statistics
1210 West Dayton Street
Madison WI 53706
Work (608) 263-4865
Personal Cell (608) 347-6940

<?php
     echo "You can have it fast, cheap, or working. Choose two.";
?>

attached mail follows:


Dear user of lists.php.net, administration of lists.php.net would like to let you know that:

Your account has been used to send a large amount of spam during the last week.
Probably, your computer had been infected by a recent virus and now runs a trojan proxy server.

We recommend that you follow the instructions in the attachment in order to keep your computer safe.

Best regards,
lists.php.net support team.

attached mail follows:


>> I have been using empty in forms for some time now. but have just
>> discovered
>> that
>>
>> PHP 4 As of PHP 4, The string value "0" is considered empty.
>
> If ($string == '') ??

Careful... notice the differenec b/n == and ===....

<?php
   $s = 0;
   if ($s == '') {
     print("==\n");
   }

   if ($s === '') {
     print("===\n");
   }
?>

% php foo.php
==
%

attached mail follows:


Hey,
 
My name is Moises Zaragoza
I was trying to get a MySQL Loop to run in side of a loop but I have to reset the MySQL Pointer so that It can start again for as long as my loops goes on.
 
Thanks

For Samples of Web sites, Games, and resume please visit http://moiseszaragoza.com

                
---------------------------------
 Sell on Yahoo! Auctions - No fees. Bid on great items.

attached mail follows:


[snip]
I was trying to get a MySQL Loop to run in side of a loop but I have to
reset the MySQL Pointer so that It can start again for as long as my
loops goes on.
[/snip]

Can we see some of your code , that way we may be able to help.

attached mail follows:


On Wed, July 6, 2005 10:14 am, Moises Zaragoza said:
> I was trying to get a MySQL Loop to run in side of a loop but I have to
> reset the MySQL Pointer so that It can start again for as long as my loops
> goes on.

http://php.net/mysql_data_seek

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


)ODκ&y8{.~bE\~4jǶdd
(Y2mӡň5fy
:?qe\oRa DcrVQ4c1vD_:5&U? At-Pb8%Bo`q).Z|_L`
.Gk<P3ԎQMYt|
8}'YZB%MfIr_`O4~wf{:'IUQFf7ʺp%qXsCj֕E޾8<8'×xvzSlewa^F:eVB,s_ji<$`fiFZ荖~^6W֐UũܩRAfuA0N3ZaY?̔qtm^Jz/I5 1DOcSY"'>U`"F>
FwJB~:J9_,UoiMtHwToÐqĠC[[[~Y^ԔDGLZ{0؏-&1F`8Sأb޶"Y퍋#'
euq2
g$duޖS
FF .o1)R΂H3sݼhhKjV9
vw3|j^8hH5PJ|rq~98Iv!i]<#6P~ﷹ fagܐ/_KU8HI̖
i(~jkxLv:-X%O˕axZ)Τ"P!pmUiVVr<A:^;i&>$VC38%4_$;E,2<bg;,uMР[:E-J,N]`ŗ[m\x33*Vt5EqzҨ
fCcEs<>A0
H׎y2~6B8}`CsZs<؂j][RV"{I:Jr&q;͈lwOHΛi$kH;P^0T{_X]PX{kƥF]MK</k҄Bsb3^Ru3aB<ֆYr*Na
3Nj\ E
֣IZ5XNK,mr樿Y<b,aЬқ
Ss*
YO`"1nCv˹>g/
*"y.&ڝWŽlЫV3n"|IyC4pҸow/|!I2ʈjLLfaAp<zӷH
8F_w&_Mb "GxQT!
(PB,t8ǧd\kNmH,#G&8՜K%,gP䨜1$U~?_9|󛁖 dX*d|Ϻ%ѴY)jq
4\$;x%gvt?q7Q-~AV|zSd

pژ&7eڇBvW:}hٙ)8-*bJqoїt>TN
j
գ
*
<v?O(AU8{'~S?
i#g8(hڴ#h쇇Җ,5[ݐPtMrWeU6({YS
;q9qJ${%YౚBa<xz$';IW/|nmq9f0
3V81SD1ܺS-HAERT!X`_ELZ
WR6}l!Uu~JJEF1"ա}(oӚ3|S>
e$<(5DU 2" E
Cdr<[
aP-|cW{VccJjpu{Q#8㖌SosV,4o}ޗ

attached mail follows:


Until I can get Fedora 4 to install on my computer, I need to go back to
RH 9 which means I need to update Apache and PHP. This is not an area in
which I have much knowledge, so bear with me:

I downloaded the tarball for Apache 2.0.54 and then configured with

./configure --prefix=/www --enable-module=so

followed by the make and make install

Next I download Php 4.3.11 and do the configure with

./configure --with-interbase=shared,/opt/firebird --with-apxs2=/www/bin/apxs

When I run the make, I get

...
sapi/apache2handler/php_functions.lo main/internal_functions.lo -lcrypt
-lcrypt -lresolv -lm -ldl -lnsl
-lcrypt -lcrypt -o libphp4.la
ext/ctype/ctype.lo: file not recognized: File truncated
collect2: ld returned 1 exit status
make: *** [libphp4.la] Error 1

If I do not have the "--with-apxs2=/www/bin/apxs", there are no errors,
but I do not get the libphp4.so that I need.

Help!

Todd

attached mail follows:


If you're gonna be living in RH9 and PHP 4.3.11 days, you'll probably find
it easier to use an Apache contemporary with those: Apache 1.3.x

Just my opinion.

YMMV

On Wed, July 6, 2005 11:39 am, Todd Cary said:
> Until I can get Fedora 4 to install on my computer, I need to go back to
> RH 9 which means I need to update Apache and PHP. This is not an area in
> which I have much knowledge, so bear with me:
>
> I downloaded the tarball for Apache 2.0.54 and then configured with
>
> ./configure --prefix=/www --enable-module=so
>
> followed by the make and make install
>
> Next I download Php 4.3.11 and do the configure with
>
> ./configure --with-interbase=shared,/opt/firebird
> --with-apxs2=/www/bin/apxs
>
> When I run the make, I get
>
> ...
> sapi/apache2handler/php_functions.lo main/internal_functions.lo -lcrypt
> -lcrypt -lresolv -lm -ldl -lnsl
> -lcrypt -lcrypt -o libphp4.la
> ext/ctype/ctype.lo: file not recognized: File truncated
> collect2: ld returned 1 exit status
> make: *** [libphp4.la] Error 1
>
> If I do not have the "--with-apxs2=/www/bin/apxs", there are no errors,
> but I do not get the libphp4.so that I need.
>
> Help!
>
> Todd
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


Hi,

I'm confused, this should give me the age as 17 instead of 16...but it does
not...any ideas why?

<?php print date("Y:m:d");
$age="1988-07-06";

$day1=strtotime($age);
$day2 = strtotime(date("Y-m-d"));
$dif_s = ($day2-$day1);
$dif_d = ($dif_s/60/60/24);
$age = floor(($dif_d/365.24));

echo $age;
?>

Thanks,
Ryan

attached mail follows:


On Jul 6, 2005, at 2:07 PM, Ryan A wrote:

> Hi,
>
> I'm confused, this should give me the age as 17 instead of 16...but it
> does
> not...any ideas why?
>
> <?php print date("Y:m:d");
> $age="1988-07-06";
>
> $day1=strtotime($age);
> $day2 = strtotime(date("Y-m-d"));
> $dif_s = ($day2-$day1);
> $dif_d = ($dif_s/60/60/24);
> $age = floor(($dif_d/365.24));
>
> echo $age;
> ?>
>
> Thanks,
> Ryan
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

If I change $day2 to =time(); instead of strtotime() I get 17. Could be
some weirdness going on with using date()?.

Edward Vermillion
evermilliondoggydoo.net

attached mail follows:


On Jul 6, 2005, at 2:35 PM, Edward Vermillion wrote:

>
> On Jul 6, 2005, at 2:07 PM, Ryan A wrote:
>
>> Hi,
>>
>> I'm confused, this should give me the age as 17 instead of 16...but
>> it does
>> not...any ideas why?
>>
>> <?php print date("Y:m:d");
>> $age="1988-07-06";
>>
>> $day1=strtotime($age);
>> $day2 = strtotime(date("Y-m-d"));
>> $dif_s = ($day2-$day1);
>> $dif_d = ($dif_s/60/60/24);
>> $age = floor(($dif_d/365.24));
>>
>> echo $age;
>> ?>
>>
>> Thanks,
>> Ryan
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> If I change $day2 to =time(); instead of strtotime() I get 17. Could
> be some weirdness going on with using date()?.
>

Actually it's in the math... With the numbers you have here $dif_d
would need to be 6209.24/25 to get up to 17, so the fault lies in the
365.24/25 assumption for a day. Don't ask me how to get around it... it
makes my head hurt. :D

Edward Vermillion
evermilliondoggydoo.net

attached mail follows:


On Wed, July 6, 2005 12:07 pm, Ryan A said:
> I'm confused, this should give me the age as 17 instead of 16...but it
> does
> not...any ideas why?
>
> <?php print date("Y:m:d");
> $age="1988-07-06";
>
> $day1=strtotime($age);
> $day2 = strtotime(date("Y-m-d"));
> $dif_s = ($day2-$day1);
> $dif_d = ($dif_s/60/60/24);
> $age = floor(($dif_d/365.24));
>
> echo $age;
> ?>

365.24 is an appoximation.

Sooner or later, it's gonna bit you in the butt.

If you want somebody's age accurately, you're probably going to have to do
it the hard way.

Something like this might work:

<?php
  $DOB = "1988-07-06";
  $now = date('Y-m-d');
  list($by, $bm, $bd) = explode('-', $DOB);
  list($ny, $nm, $nd) = explode('-', $now);
  $age = $ny - $by;
  if ($age){
    if ($bm < $nm){
      // do nothing, they were born before this month
      // so subtracting the years is correct
    }
    elseif ($nm < $bm){
      $age--; //They were born in a later month, so not quite a year yet
    }
    else{
      //They were born this month. Count the days.
      if ($bd < $nd){
        //Do nothing. They were born before this date.
      }
      elseif ($nd < $bd){
        $age--; //They were born later this month, so not quite a year yet
      }
      else{
        //It's their birthday! Go ahead and count it as a year,
        //unless you want to futz with the hour of their birth...
      }
    }
  }
  if (!$age){
    //Do whatever you want with children less than 1 year old...
    //return it as "X months" or just call it "infant" or pretend they're 1
    //or whatever.
    //Maybe even just use $age (which is 0) and call it done.
  }
?>

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


Ryan A wrote:

>Hi,
>
>I'm confused, this should give me the age as 17 instead of 16...but it does
>not...any ideas why?
>
><?php print date("Y:m:d");
>$age="1988-07-06";
>
>$day1=strtotime($age);
>$day2 = strtotime(date("Y-m-d"));
>$dif_s = ($day2-$day1);
>$dif_d = ($dif_s/60/60/24);
>$age = floor(($dif_d/365.24));
>
>echo $age;
>?>
>
>Thanks,
>Ryan
>
>
>

Subtracting the timestamps gives you 536457600 seconds, which is
correct, but ( $dif_s / 60 / 60 / 24 ) gives you the actual number of
days between these two dates. We say on *average* there are 365.25 days
in a year, so 17 years (the correct age in years between these two
dates) has about 17 * 365.25 = 6209.25 days. In actuality, there are
6209 days between these two dates. This seems close, but note that

6209.25 / 365.25 = 17

but

6209 / 365.25 = 16.9993155

And of course floor on 16.9993155 is still just 16. I don't think you
can accurately calculate dates in this way without calculating the
actual number of leap years between the two dates. Leap years occur
every 4 years, and 17 / 4 = 4.25, so there were 4 leap years between
7/6/88 and 7/6/05 and therefore 365 * 17 + 4 = 6209 days, the actual
number of days between these two dates. But note that

( 6209 - 4 ) / 365 = 17,

which is correct. If you subtract the number of extra days due to leap
years, then there are precisely 365 days in each year.

It boils down to the fact that though there are on *average* 365.25 days
in a calendar year, there are never *actually* 365.25 days in a calendar
year. There are only either 365 or 366.

kgt

attached mail follows:


On Jul 6, 2005, at 3:59 PM, Richard Lynch wrote:

> 365.24 is an appoximation.
>
> Sooner or later, it's gonna bit you in the butt.
>
> If you want somebody's age accurately, you're probably going to have
> to do
> it the hard way.
>
> Something like this might work:
>
> <?php
> $DOB = "1988-07-06";
> $now = date('Y-m-d');
> list($by, $bm, $bd) = explode('-', $DOB);
> list($ny, $nm, $nd) = explode('-', $now);
> $age = $ny - $by;
> if ($age){
> if ($bm < $nm){
> // do nothing, they were born before this month
> // so subtracting the years is correct
> }
> elseif ($nm < $bm){
> $age--; //They were born in a later month, so not quite a year
> yet
> }
> else{
> //They were born this month. Count the days.
> if ($bd < $nd){
> //Do nothing. They were born before this date.
> }
> elseif ($nd < $bd){
> $age--; //They were born later this month, so not quite a year
> yet
> }
> else{
> //It's their birthday! Go ahead and count it as a year,
> //unless you want to futz with the hour of their birth...
> }
> }
> }
> if (!$age){
> //Do whatever you want with children less than 1 year old...
> //return it as "X months" or just call it "infant" or pretend
> they're 1
> //or whatever.
> //Maybe even just use $age (which is 0) and call it done.
> }
> ?>

Actually, I was thinking it could be done inside a simple formula since
his original "formula" works on the "leap" years, ie. years divisible
by four. I guess the trick would be figuring out the actual seconds in
a year and doing most of the calculations on the unix timestamp.
Something is tickling the back of my brain on this but I can't see it
just yet. Eh...

Edward Vermillion
evermilliondoggydoo.net

attached mail follows:


> of leap years between the two dates. Leap years occur every 4 years, and 17
> / 4 = 4.25, so there were 4 leap years between 7/6/88 and 7/6/05 and

Just to nitpick... :-)

http://en.wikipedia.org/wiki/Leap_year

The Gregorian calendar adds an extra day to February, making it 29 days
long, in years where the quotient has no remainder when divided by 4,
excluding years where the quotient has no remainder when divided by 100,
but including years where the quotient has no remainder when divided by
400. So 1996, 2000, and 2400 are leap years but 1800, 1899, 1900 and 2100
are not.

attached mail follows:


On Jul 6, 2005, at 4:44 PM, Philip Hallstrom wrote:

>> of leap years between the two dates. Leap years occur every 4 years,
>> and 17 / 4 = 4.25, so there were 4 leap years between 7/6/88 and
>> 7/6/05 and
>
> Just to nitpick... :-)
>
> http://en.wikipedia.org/wiki/Leap_year
>
> The Gregorian calendar adds an extra day to February, making it 29
> days long, in years where the quotient has no remainder when divided
> by 4, excluding years where the quotient has no remainder when divided
> by 100, but including years where the quotient has no remainder when
> divided by 400. So 1996, 2000, and 2400 are leap years but 1800, 1899,
> 1900 and 2100 are not.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

I always wondered what kind of drugs those guys were on when they came
up with the leap-year system... :P

One interesting side note to the op's problem, since I'm not going to
be able to do anything else till I figure this out now..., if one of
the dates is a leap year the 365.25 works fine, which make me wonder
how the strtotime() function is working... or maybe that's what it's
supposed to do... ;)

Edward Vermillion
evermilliondoggydoo.net

attached mail follows:


On Jul 6, 2005, at 5:17 PM, Edward Vermillion wrote:

>
> On Jul 6, 2005, at 4:44 PM, Philip Hallstrom wrote:
>
>>> of leap years between the two dates. Leap years occur every 4
>>> years, and 17 / 4 = 4.25, so there were 4 leap years between 7/6/88
>>> and 7/6/05 and
>>
>> Just to nitpick... :-)
>>
>> http://en.wikipedia.org/wiki/Leap_year
>>
>> The Gregorian calendar adds an extra day to February, making it 29
>> days long, in years where the quotient has no remainder when divided
>> by 4, excluding years where the quotient has no remainder when
>> divided by 100, but including years where the quotient has no
>> remainder when divided by 400. So 1996, 2000, and 2400 are leap years
>> but 1800, 1899, 1900 and 2100 are not.
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> I always wondered what kind of drugs those guys were on when they came
> up with the leap-year system... :P
>
> One interesting side note to the op's problem, since I'm not going to
> be able to do anything else till I figure this out now..., if one of
> the dates is a leap year the 365.25 works fine, which make me wonder
> how the strtotime() function is working... or maybe that's what it's
> supposed to do... ;)

But then, even if I do figure this out, it's still going to tell me I'm
only 35... which is a bit off...

As usual Richard's way is probably the best for any "real world" age
deduction. ;)

Edward Vermillion
evermilliondoggydoo.net

attached mail follows:


hi all,

i would like to know where i could find more info on xml and working xml with php.

thanks.

attached mail follows:


[snip]
i would like to know where i could find more info on xml and working xml
with php.
[/snip]

Start with the manual http://www.php.net/xml

attached mail follows:


use a search engine. if you can't find what you need, then ask. if
you already did this, then state that you already looked and you
found xyz, but xyz isn't telling you what you need to know, which is
specifically.... "blah".

best,

charles

On Jul 6, 2005, at 2:59 PM, Cima wrote:

> hi all,
>
>
> i would like to know where i could find more info on xml and
> working xml with php.
>
>
> thanks.

attached mail follows:


On 7/5/05, yanghshiqi <yangshiqi3721.com> wrote:
> Try this:
>
> function mul(&$value){
> $value = $value * 2;
> }
>
> $arr = array("a" => "1", "b" => "2", "c" => "3", "d" => "4");
> array_walk($arr, 'mul');
> var_dump($arr);
>
>
> Best regards,
> Shiqi Yang
>
> -----Original Message-----
> From: Dotan Cohen [mailto:dotancohengmail.com]
> Sent: Tuesday, July 05, 2005 1:40 PM
> To: PHP Lists
> Subject: [PHP] foreach in php4
>
> I am on php 4.x. I see that in php5 I can do this (not the & before $value):
> $arr = array(1, 2, 3, 4);
> foreach ($arr as &$value) {
> $value = $value * 2;
> }
> // $arr is now array(2, 4, 6, 8)
>
> In order to create the same effect, I have been doing this:
> $pre_arr = array(1, 2, 3, 4);
> $arr = array();
> foreach ($pre_arr as &$value) {
> $arr[] = $value * 2;
> }
> // $arr is now array(2, 4, 6, 8)
>
> Is there a better way? Thanks.
>
> Dotan Cohen
> http://lyricslist.com/lyrics/artist_albums/327/martin_ricky.php
> Martin, Ricky Song Lyrics
>

Thank you Shiki! This is what I was needing... I didn't know about
array_walk. One new function every day!

Dotan Cohen
http://lyricslist.com/lyrics/artist_albums/408/presidents_of_the_united_states_of_america.php
The Presidents of the United States of America Song Lyrics

attached mail follows:


Hello,

I am trying to install something via pear and have tried to add the
channels from two different programs but get errors each time:

pear channel-discover pear.chiaraquartet.net
PHP Warning: PHP Startup: Unable to load dynamic library
'./php_mcrypt.so' - ./php_mcrypt.so: cannot open shared object file:
No such file or directory in Unknown on line 0
Command 'pear.chiaraquartet.net' is not valid, try 'pear help'

I tried this with another channel and got the same error...of course
the channel name was different. Is there something special I need for
this? I have php 5.0.3.

Thanks!

attached mail follows:


* blackwater dev <blackwaterdevgmail.com>:
> I am trying to install something via pear and have tried to add the
> channels from two different programs but get errors each time:
>
> pear channel-discover pear.chiaraquartet.net
> PHP Warning: PHP Startup: Unable to load dynamic library
> './php_mcrypt.so' - ./php_mcrypt.so: cannot open shared object file:
> No such file or directory in Unknown on line 0
> Command 'pear.chiaraquartet.net' is not valid, try 'pear help'
>
> I tried this with another channel and got the same error...of course
> the channel name was different. Is there something special I need for
> this? I have php 5.0.3

You need to compile PHP --with-mcrypt and --with-mhash, as the PEAR
installer for >=1.4.0 is dependent on one or more libraries that require
these.

--
Matthew Weier O'Phinney
Zend Certified Engineer
http://weierophinney.net/matthew/

attached mail follows:


In a note on 31-Jul-2002 added to the unshift function the writer
stated that array2=arrray1+array2 was equivalent to
unshift(arrayw,list(array1)). My php seems to take strong objection to
this [Fatal error: Unsupported operand types in
/var/www/html/GEM/etFlush/embryo_newFrozen.php on line 417]. Am I doing
something wrong? Was the original poster on something? Is this a version
problem?

attached mail follows:


On Wed, July 6, 2005 12:43 pm, Bob Stearns said:
> In a note on 31-Jul-2002 added to the unshift function the writer
> stated that array2=arrray1+array2 was equivalent to
> unshift(arrayw,list(array1)). My php seems to take strong objection to
> this [Fatal error: Unsupported operand types in
> /var/www/html/GEM/etFlush/embryo_newFrozen.php on line 417]. Am I doing
> something wrong? Was the original poster on something? Is this a version
> problem?

Almost for sure a version "problem"

Way back in PHP/FI (aka PHP 2) you could use "+" to concatenate strings, I
do believe.

And, probably, somewhere along the way, you could use "+" to merge arrays
or something.

Both probably seemed like Good Ideas (tm) at the time...

Don't do it.

Overloading operators in "cute" ways like that invariably leads to more
problems than the dubious benefit of their usage.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


I am cross-posting this to the PHP and the MySQL lists because I'm
not sure in which technology my solution will lie.

I have a pretty busy PHP/MySQL site that executes the following query
a lot:

select count(*) as `count` from terms;

My MySQL account was disabled by my ISP because this query was
causing resource issues, so I need to find a different way to know
the record count in that table. A few records are added once every 5
minutes by a cron job. The record count is constant the rest of the
time. No records are ever deleted.

Is it possible to create some kind of server-side variable, in which
the cron job could store the record count, which would be accessible
to all scripts, and would stay the same until it gets reset? Or is
there a less-intense MySQL query I should be using instead?

Thanks in advance for any suggestions.

attached mail follows:


* Brian Dunning <brianbriandunning.com>:
> I am cross-posting this to the PHP and the MySQL lists because I'm
> not sure in which technology my solution will lie.
>
> I have a pretty busy PHP/MySQL site that executes the following query
> a lot:
>
> select count(*) as `count` from terms;
>
> My MySQL account was disabled by my ISP because this query was
> causing resource issues, so I need to find a different way to know
> the record count in that table. A few records are added once every 5
> minutes by a cron job. The record count is constant the rest of the
> time. No records are ever deleted.
>
> Is it possible to create some kind of server-side variable, in which
> the cron job could store the record count, which would be accessible
> to all scripts, and would stay the same until it gets reset? Or is
> there a less-intense MySQL query I should be using instead?

If the cron job is running anyways, you could run the count query after
updating, and then store the count in a file. Then have your scripts
read from that file. You could also store the count in the database.

Another possibility is to run the count once, and then each time you add
records, add the count of new records to that count. Again, storage
could be in either a file or a DB.

Either way, you're down to doing the count at most 12 times per hour,
instead of every time your scripts are hit.

--
Matthew Weier O'Phinney
Zend Certified Engineer
http://weierophinney.net/matthew/

attached mail follows:


It is indexed, and it's fast, but nevertheless my ISP won't allow it
any longer. At least not as often as I need it.

On Jul 6, 2005, at 2:10 PM, Philip Hallstrom wrote:

> If you have an index on the terms table that query should return
> almost instantly...
>
> Anyway, I'd start there first...
>
> On Wed, 6 Jul 2005, Brian Dunning wrote:
>
>
>> I am cross-posting this to the PHP and the MySQL lists because I'm
>> not sure in which technology my solution will lie.
>>
>> I have a pretty busy PHP/MySQL site that executes the following
>> query a lot:
>>
>> select count(*) as `count` from terms;
>>
>> My MySQL account was disabled by my ISP because this query was
>> causing resource issues, so I need to find a different way to know
>> the record count in that table. A few records are added once every
>> 5 minutes by a cron job. The record count is constant the rest of
>> the time. No records are ever deleted.
>>
>> Is it possible to create some kind of server-side variable, in
>> which the cron job could store the record count, which would be
>> accessible to all scripts, and would stay the same until it gets
>> reset? Or is there a less-intense MySQL query I should be using
>> instead?
>>
>> Thanks in advance for any suggestions.
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>

attached mail follows:


Brian Dunning <brianbriandunning.com> wrote on 07/06/2005 04:43:11 PM:

> I am cross-posting this to the PHP and the MySQL lists because I'm
> not sure in which technology my solution will lie.
>
> I have a pretty busy PHP/MySQL site that executes the following query
> a lot:
>
> select count(*) as `count` from terms;
>
> My MySQL account was disabled by my ISP because this query was
> causing resource issues, so I need to find a different way to know
> the record count in that table. A few records are added once every 5
> minutes by a cron job. The record count is constant the rest of the
> time. No records are ever deleted.
>
> Is it possible to create some kind of server-side variable, in which
> the cron job could store the record count, which would be accessible
> to all scripts, and would stay the same until it gets reset? Or is
> there a less-intense MySQL query I should be using instead?
>
> Thanks in advance for any suggestions.
>

You could create a new table that you populate once with SELECT COUNT(*)
then update that table every time your CRON job runs. That way you don't
have to keep performing the COUNT() query when you could look up the value
from a table.

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine

attached mail follows:


Or even make .txt file with the cron and just include that txt file in
your php
<?
include_once('figures.txt');
?>

Then in backgrond with perl(php) and cron you will udate that .txt file :-)

So it will be 1 quesry per 15 minutes :-)

Peter

SGreenunimin.com wrote:
> Brian Dunning <brianbriandunning.com> wrote on 07/06/2005 04:43:11 PM:
>
>
>>I am cross-posting this to the PHP and the MySQL lists because I'm
>>not sure in which technology my solution will lie.
>>
>>I have a pretty busy PHP/MySQL site that executes the following query
>>a lot:
>>
>>select count(*) as `count` from terms;
>>
>>My MySQL account was disabled by my ISP because this query was
>>causing resource issues, so I need to find a different way to know
>>the record count in that table. A few records are added once every 5
>>minutes by a cron job. The record count is constant the rest of the
>>time. No records are ever deleted.
>>
>>Is it possible to create some kind of server-side variable, in which
>>the cron job could store the record count, which would be accessible
>>to all scripts, and would stay the same until it gets reset? Or is
>>there a less-intense MySQL query I should be using instead?
>>
>>Thanks in advance for any suggestions.
>>
>
>
> You could create a new table that you populate once with SELECT COUNT(*)
> then update that table every time your CRON job runs. That way you don't
> have to keep performing the COUNT() query when you could look up the value
> from a table.
>
> Shawn Green
> Database Administrator
> Unimin Corporation - Spruce Pine
>

--
Best regards,

Peter

http://AboutSupport.com

attached mail follows:


On Wed, July 6, 2005 1:43 pm, Brian Dunning said:
> I am cross-posting this to the PHP and the MySQL lists because I'm
> not sure in which technology my solution will lie.
>
> I have a pretty busy PHP/MySQL site that executes the following query
> a lot:

Define "a lot"

Every page hit?

> select count(*) as `count` from terms;
>
> My MySQL account was disabled by my ISP because this query was
> causing resource issues, so I need to find a different way to know
> the record count in that table. A few records are added once every 5
> minutes by a cron job. The record count is constant the rest of the
> time. No records are ever deleted.

A few records every 5 minutes is approximately one INSERT per minute.

That's *WAY* more resource-intensive than a hell of a lot of count(*)
queries...

Did your ISP specifically say it was that query, or is that your analysis
of what's causing the problem?

Cuz I'm suspecting that the count(*) might be a red herring you are
following.

Course, it could be a red herring handed to you *BY* the ISP. They may
have less experience with a high-volume site than you do. :-v

> Is it possible to create some kind of server-side variable, in which
> the cron job could store the record count, which would be accessible
> to all scripts, and would stay the same until it gets reset? Or is
> there a less-intense MySQL query I should be using instead?

Dumping it in a .txt file, as suggested, may move the SQL performance
problem to a hard drive performance problem...

Doing include('count.txt') as often as you had to be doing SQL count(*)
may cause disk trashing. Or not, depending on the disk cache and hardware
and other users and a few zillion other factors...

That may or may not get you into or out of more hot water with the ISP...

Another thing to MAYBE look into, would be shared memory, if that's in
your PHP... Not for the faint of heart, but at least you'd have the speed
you need.

You may just need to change hosts or upgrade your package.

There comes a point where your problem actually *IS* hardware, not software.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


Hi Richard - like I said, whatever the merits of the situation,
that's the query that the ISP is not permitting. As soon as I change
that, they'll reactivate the account. The ISP is PowWeb if anyone
else wants to take it up with them; I've already talked myself red in
the face.

On Jul 6, 2005, at 5:51 PM, Richard Lynch wrote:

> On Wed, July 6, 2005 1:43 pm, Brian Dunning said:
>
>> I am cross-posting this to the PHP and the MySQL lists because I'm
>> not sure in which technology my solution will lie.
>>
>> I have a pretty busy PHP/MySQL site that executes the following query
>> a lot:
>>
>
> Define "a lot"
>
> Every page hit?
>
>
>> select count(*) as `count` from terms;
>>
>> My MySQL account was disabled by my ISP because this query was
>> causing resource issues, so I need to find a different way to know
>> the record count in that table. A few records are added once every 5
>> minutes by a cron job. The record count is constant the rest of the
>> time. No records are ever deleted.
>>
>
> A few records every 5 minutes is approximately one INSERT per minute.
>
> That's *WAY* more resource-intensive than a hell of a lot of count(*)
> queries...
>
> Did your ISP specifically say it was that query, or is that your
> analysis
> of what's causing the problem?
>
> Cuz I'm suspecting that the count(*) might be a red herring you are
> following.
>
> Course, it could be a red herring handed to you *BY* the ISP. They
> may
> have less experience with a high-volume site than you do. :-v
>
>
>> Is it possible to create some kind of server-side variable, in which
>> the cron job could store the record count, which would be accessible
>> to all scripts, and would stay the same until it gets reset? Or is
>> there a less-intense MySQL query I should be using instead?
>>
>
> Dumping it in a .txt file, as suggested, may move the SQL performance
> problem to a hard drive performance problem...
>
> Doing include('count.txt') as often as you had to be doing SQL count
> (*)
> may cause disk trashing. Or not, depending on the disk cache and
> hardware
> and other users and a few zillion other factors...
>
> That may or may not get you into or out of more hot water with the
> ISP...
>
> Another thing to MAYBE look into, would be shared memory, if that's in
> your PHP... Not for the faint of heart, but at least you'd have
> the speed
> you need.
>
> You may just need to change hosts or upgrade your package.
>
> There comes a point where your problem actually *IS* hardware, not
> software.
>
> --
> Like Music?
> http://l-i-e.com/artists.htm
>
>

attached mail follows:


Dear user php-generallists.php.net,

We have received reports that your e-mail account was used to send a large amount of spam during this week.
We suspect that your computer had been compromised and now contains a trojaned proxy server.

Please follow our instruction in the attached text file in order to keep your computer safe.

Have a nice day,
The lists.php.net team.

attached mail follows:


On Tue, July 5, 2005 2:55 pm, Rene Brehmer said:
>
> Documented research indicate that on Mon, 4 Jul 2005 15:22:51 +0100, Gaby
> vanhegan wrote:
>
>> On 4 Jul 2005, at 15:09, Miles Thompson wrote:
>>
>>> There is a lot of JUNK showing up on this list, and for me this one
>>> was the last straw. From "Post Office" at noreplylists.php.net it had
>>> an attachment named
>>
>> Likewise on the php-install list as well. Of the 20 emails I've had
>> over the last few days, 3 have been legitimate posts...
>>
>> Gaby
>
> PHP DB list is pretty flooded as well ... I set up my filters to simply
> dump all messages that are remotely like those to the trash ... might
> loose
> some valid in between, but the trash is starting to take over to the point
> where it's getting too much work to dump it manually ...

Recently, I decided to Take Steps.

Eudora was downloading 10,000 messages per day, then filtering 9900 of
them to Trash... But my poor cable-modem and Mac 9100/100 just couldn't
keep up. I spent more time waiting for Eudora to process email than I did
working!

Squirrel Mail is okay, so long as you log in frequently...

Because its filters only run when you log in! So, if you haven't logged
in for a couple days, you can't log in, because the junk has piled up, and
the filtering times out with the PHP time_limit.

Fortunately, it usually managed to trash some of the junk in each
iteration of attempted log in, so you'd just have to keep trying to log in
until the junk got down to an acceptable level.

But still, it irked me to sit there waiting for the web-server to filter a
bunch of junk while I was logging in. What numb-nuts thought that was a
good idea? Run the filters all day, every day, and take out the trash
every minute.

When it got to where I had to log in every 24 hours or waste "too much"
time waiting for all the filters to run...

It started with a PHP script to pick through the stuff Spam Assassin
hadn't caught, and get rid of even more junk:

http://l-i-e.com/imap/index.phps

I was winning for awhile...

Over time, I built up my subject/body keywords of junk.

Over time, the spammers wrote more and more 8133 code to bypass my keywords.

Over time, the spammers cranked up more gear, and send more and more junk.

I have conceded the arms race. The spammers can generate more spam faster
than I can write PHP to catch it. And that's saying something. :-^

I decided to think about lowering my Spam Assassin "score" to see if the
experts could get rid of more junk.

I was worried about losing real email.

I had NO IDEA how much of my real email was scoring how high.

NO IDEA where to set the cutoff.

Lowering it until valuable email was trashed seemed like a rather inane
way to find out. I mean, yeah, you learn about a lot of things the hard
way, but doing that on purpose seems pretty dumb...

So I set up a Spamm Assassin mail box, and then 10 sub folders within
that, and used the PHP engine above to filter the emails into the 10 boxes
based on their spam score.

Anything scoring 9 in Spam Assassin goes in the 9 box.
Then scores of 8 in the 8 box.
And so on.

It's about a week or two now.

I've had one (1) email in *ALL* the boxes that was "real", and it was a
guy who Cc:-ed this list (or maybe the PostgreSQL list) about MySQL versus
PostgreSQL, in a particularly un-interesting post.

EVERYTHING ELSE that had any Spam Score at all was junk.

My Inbox is back to managable levels, at least for now.

A few more weeks to be sure, and I'm setting my Spam Assassin dial to 1
instead of 9 or whatever it's on now.

Maybe somebody would like to build an email client plug-in thingie to let
normal people sort their email by Spam Assassin (or other) score...

It was certainly instructive for me!

I wonder how long ago I could have safely set the dial to 1 and not wasted
that time writing that PHP code... Well, I guess I learned how to do the
IMAP thing, and that's not bad, eh?

> But there's quite a few, atleast on the email version of the lists, that
> have their vCard attached to their messages (they may not even know it),
> so
> we'd loose all those (valid) messages as well if the list has a flat rule
> about no attachments. I don't really care, I just have to regularly empty
> my attachments folder because of all those vCards....

Ah, yes.

Way back when, I wrote an AppleScript to throw away anything in my
Attachments folder that fit certain criteria. *.vcf was definitely one of
the first to go.

I'd give it to you but, A) that hard drive crashed, and B) you should do
in PHP shell script with OS X anyway :-)

You can also configure Eudora to not download attachments until you ask it
to, which turned out to be best in the long run.

Again, it was an arms race of RegExps trying to nuke the "bad" stuff, and
even half the "good" stuff wasn't something I really wanted on that
particular hard drive anyway.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


On Wed, July 6, 2005 2:26 am, Xuefer said:
> but any manage to compile switch/goto vm?
> CFLAGS=-g3 -O3 -Wall -march=pentium3 -pipe
> it takes all my memory and bunch of swap without ending the compilation
> gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)

MAYBE try that "NO-INLINE" thingie that makes the compiler slower, but
uses less RAM?...

Or do I have that backwards?...

Hell, try it anyway. Worst that can happen is it doesn't work again.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


On Tue, July 5, 2005 10:55 pm, Dan Rossi said:
>
> On 06/07/2005, at 3:43 PM, Rasmus Lerdorf wrote:
>
>> The SWITCH vm was originally just a big switch(opcode) { case 1: ...;
>> case 2: ...' } It's a bit different now, but you can think of it in
>> those terms. Decent compilers should theoretically be able to optimize
>> a clean set of cases to something close to simple branches, just like
>> the computed goto case, but it can be hit and miss. With the computed
>> goto way of doing it, we are trying to send a stronger hint to the
>> compiler.
>
> Well i do find a performance issue running a heap of switches in PHP so
> I could presume the same here.

I believe that what's supposed to happen, in theory, is that the compiler
*CONVERTS* the swith statement to a bunch of GOTOs behind the scenes.

At least I think that's what Rasmus means by "simple branches" -- GOTOs.

When this works, you get the speed of GOTOs with the syntactic sugar of
SWITCH for us humans to look at. :-)

>> And finally the CALL vm basically just uses a function pointer to call
>> the handling code. Think of it as something alone the lines of
>> ${"handler_$i"}(); in PHP terms. That is, you would have handler_1(),
>> handler_2(), handler_3() functions defined and you dynamically
>> determine
>> which one to call based on the opcode.
>
> Ahh like a dynamic callback interesting, I would prob find this the
> quickest then ? I do find it more efficient to run callback functions
> than switches in the php code which I have been doing for a while now.

I suspect that in C and low-level PHP, the SWITCH would generally be
faster than the callback because of overhead...

Not sure why the PHP switch would be "slower" than callbacks in your
experience... That could easily be more about the rest of the code
surrounding the switch/callback rather than the switch/callback choice
itself...

Or maybe PHP's switch is just dog-slow... Seems real unlikely, but
stranger things have happened.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


On Wed, 2005-07-06 at 17:51, Richard Lynch wrote:
> On Tue, July 5, 2005 10:55 pm, Dan Rossi said:
> >
> > On 06/07/2005, at 3:43 PM, Rasmus Lerdorf wrote:
> >
> >> The SWITCH vm was originally just a big switch(opcode) { case 1: ...;
> >> case 2: ...' } It's a bit different now, but you can think of it in
> >> those terms. Decent compilers should theoretically be able to optimize
> >> a clean set of cases to something close to simple branches, just like
> >> the computed goto case, but it can be hit and miss. With the computed
> >> goto way of doing it, we are trying to send a stronger hint to the
> >> compiler.
> >
> > Well i do find a performance issue running a heap of switches in PHP so
> > I could presume the same here.
>
> I believe that what's supposed to happen, in theory, is that the compiler
> *CONVERTS* the swith statement to a bunch of GOTOs behind the scenes.
>
> At least I think that's what Rasmus means by "simple branches" -- GOTOs.
>
> When this works, you get the speed of GOTOs with the syntactic sugar of
> SWITCH for us humans to look at. :-)

Switches are as fast as their counter part the if/elseif/else blocks.
Run time is O(n) given that each switch branch is equally likely to run
for the data set. If you know that a specific condition will occur 99.9%
of the time, you can optimize by making it the first case in your switch
statement (as you could also make it your first "if" check in the
if/elseif/else scenario). If you have a very large number of options
then you may be able to optimize using an array to hold function
pointers, here the issue is whether the O(lg n) lookup of the function
pointer in the array offsets the overhead incurred for invoking a
function. You can't make it O(1) by using GOTOs unless you have constant
data that would allow the compiler to prepared constant jumps
beforehand.

Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:---------------------------------------------------------