RE: [PHP] Trigger root script?

2005-09-26 Thread Michael Sims
Jeffrey Sambells wrote:
 I need a php script to trigger another script to run as root on a
 machine. Currently, the scripts run as the www-data user, but that
 means I can't modify any files on the system that aren't owned by
 www-data or world writable. I somehow need to trigger a php script to
 run as the root user.

I would use sudo for this.  It allows non-root users to execute only the
scripts you specify as root.  Take a look at man sudo and man visudo.
For example, if you wanted your PHP scripts to be able to run the script
/usr/bin/foo as root, you'd put an entry like the following in your
/etc/sudoers file:

www-data  ALL=NOPASSWD: /usr/bin/foo

If you can change the permissions/ownership on the file(s) in question it
might be better to create a new group to own the files and make them group
writable, then put the www-data user into the new group.

HTH

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



RE: [PHP] Re: email validation (no regex)

2005-09-22 Thread Michael Sims
J B wrote:
 On 9/21/05, Michael Sims [EMAIL PROTECTED] wrote:
 Additionally, some mail servers unconditionally accept mail
 addressed to ANY username at their domain, whether that user
 actually exists or not.  This is very bad practice, because it
 usually means the accepting MTA is a dumb host that has to forward
 all incoming mail to an internal mail server which knows which
 accounts exist, and if that server ends up rejecting the message,
 the dumb MTA creates a DSN and sends it back to the envelope
 sender (which is quite often forged).  This causes the so-called
 backscatter which results in innocent people getting bounces for
 messages they didn't send.  Nevertheless, lots of mail servers are
 configured this way, so you cannot simply assume that an account is
 real just because you didn't get a 5xx on RCPT TO.

   Just as a side note, and I do agree that this behaviour is bad
 practice in principle, but I imagine they (the MTAs) do this for the
 same reason that login prompts don't tell you when you enter a bogus
 username and still prompt for the password and give a generic access
 denied error...it prevents username fishing.

There probably are a few people who accept mail to any address at their domain 
to
foil dictionary attacks, but IMHO the vast majority of servers that are set up 
this
way are due to mail admins who just don't know any better.  It's not always 
easy to
set up a border MTA so that it knows about the accounts that exist on an 
internal
machine...it usually involves custom scripting or real-time callouts to the 
internal
server and it takes a relatively knowledgeable admin to implement it (at least 
that
has been my experience).

I had someone else email me privately saying that they did the above precisely 
to
foil dictionary attacks, but this person configured his server to simply discard
email to nonexistent accounts.  That has it's disadvantages (since it could make
legit senders believe their messages are being delivered when they aren't) but 
it
least it doesn't create any backscatter.  In the default case, accepting all 
email
unconditionally then later rejecting it is just irresponsible, since it makes 
you a
vector for abuse, and could eventually get you blacklisted if other mail 
servers get
sick of receiving bogus bounces from your domain...

(As a side note, apparently the list software doesn't like the offtopic nature 
of
this sub-thread (I just received a 550 on this message), so this will be my last
post on the matter.  But since I've gone to the trouble of typing it up let me 
throw
in the words PHP, web, and Apache, so this will make it through. :) )

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



RE: [PHP] Max execution time while doing DB queries

2005-09-22 Thread Michael Sims
Jeroen Geusebroek wrote:
 I was wondering how i can limit a script from waiting too long for
 a database query to return.

 The problem is that it will wait an infinite time while performing a
 query on a database when there is for example a lock on a table. I
 want it to exit/fail when a set amount of time has passed.

What RDBMS are you using?  If you are using Postgres you can use pg_send_query()
which is non-blocking.  I don't think the other database backends/php drivers
support such functionality, but I could be wrong...  Maybe someone else knows of
another way to accomplish this with the other backends...

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



RE: [PHP] Max execution time while doing DB queries

2005-09-22 Thread Michael Sims
Jeroen Geusebroek wrote:
 For this application i'm using a MSSQL database. There is an ini
 setting (mssql.timeout) which should do what i want but afiak doesn't
 work. It defaults to 60 which i assume are seconds.

 My app has had times that it was waiting way longer then that before
 it died without any error message. (6 hours and more).

What platform/driver?  If Linux, are you using FreeTDS and if so what version?  
It
looks like the timeout is handled in the TDS library, not at the PHP level.  I 
did
some poking through the FreeTDS mailing list archives and it seems that PHP 
calls
dbsettime() which was unimplemented in FreeTDS in earlier versions, so you may 
need
a bleeding edge version of FreeTDS to use it.  If you are using FreeTDS you may 
want
to ask for help on the their mailing list.

If you're using Windows with the SQL Client Tools DLL then I'm not sure why the
queries aren't timing out...

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



RE: [PHP] email validation (no regex)

2005-09-21 Thread Michael Sims
Jim Moseby wrote:
 There's no requirement for an MX-record, so you'd need to check the
 A-record ($domain) too.

 Excellent answer.  No requirement for MX record?

 [showing my ignorance]
 How does email routing happen if there is no mail exchanger in the
 zonefile for a particular domain?
 [/ignorance]

Most all mail transfer agents will fall back to looking for an A record if an MX
record doesn't exist.  It's good practice to define an MX record but it isn't
required...

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



RE: [PHP] Re: email validation (no regex)

2005-09-21 Thread Michael Sims
Philip Hallstrom wrote:
 but you could do what you want to do. however, it's going to be
 painful if you want it to match the rfc spec...

 Really?  Why does it need to be painful?  I just need to do a
 'EHLO', 'Mail From:' and 'RCPT to:' and 'QUIT'. It's not going to
 actually send an email. Seems simple to me.  Maybe there's something
 else in the spec that I don't see?

 Some mail servers can be configured to not reject the email until the
 end of DATA.  I know you can do this in postfix.

 Although if the user is invalid, why you'd wait I don't know, but it
 is possible.

Additionally, some mail servers unconditionally accept mail addressed to ANY
username at their domain, whether that user actually exists or not.  This is 
very
bad practice, because it usually means the accepting MTA is a dumb host that 
has
to forward all incoming mail to an internal mail server which knows which 
accounts
exist, and if that server ends up rejecting the message, the dumb MTA creates 
a
DSN and sends it back to the envelope sender (which is quite often forged).  
This
causes the so-called backscatter which results in innocent people getting 
bounces
for messages they didn't send.  Nevertheless, lots of mail servers are 
configured
this way, so you cannot simply assume that an account is real just because you
didn't get a 5xx on RCPT TO.

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



RE: [PHP] Re: Suggestions for class design

2005-09-20 Thread Michael Sims
Murray @ PlanetThoughtful wrote:
 Once he understands how to solve class abstraction problems such as
 the one he is asking about, he will be better equipped to deal with a
 wider range of application development tasks.

I agree with this.

 This is not to trivialize your Metastorage project (or, to be more
 accurate, I know nothing about it, so it's not my place to trivialize
 it or otherwise), but to point out that 'out-of-the-box' solutions to
 fundamental coding development problems probably ultimately makes for
 a poorer programmer. I could well be wrong, but it seems this is a
 case of give a man a fish as opposed to teach a man to fish.

I see your point, but I'm not so sure I agree fully.  Manuel suggested
Metastorage (which makes sense, it's his project and he's most
familiar/comfortable with it), I suggested Propel because that is what I've
used.  I think we both suggested existing ORM's for the same reason...
namely that properly implementing a full featured ORM is an extremely
difficult thing to get right.  I don't know anything about Chris's skill as
a programmer, but he's bound to reinvent the wheel several times over, and
poorly to boot.  I believe that implementing an ORM is one of those things
that you cannot fully understand and appreciate until you've tried to do it
and failed.  IMHO it's only after you've built one that you realize what you
really need, and by then it needs to be rebuilt.  It's kind of like Fred
Brook's plan to throw one away; you will, anyhow, or at least it was for
me.

I think the whole DAO/ORM approach is something that most programmers who
are fans of OO stumble into as part of their natural development.  I know
that in my earlier projects I had implemented some type of this pattern
without fully realizing that I had done so.  It's just natural to consider
at some point that you should represent entities in your database as objects
(if you're an OO proponent).  In one of my earlier PHP projects, I
implemented a very basic ORM that represented only single entities and
didn't quite handle multiple entities very well, or the relationships
between entities (this seems to be where Chris is currently).  Then for the
next project I added better support for multiple entities and relationships,
but it was a half implementation, because I didn't represent the related
entities as full objects (for example, if a Customer has a list of phone
numbers, I had the Customer object return them as an array of strings rather
than an array of PhoneNumber objects).  I also had no support for recursion
when saving or updated objects (for example, in Propel, you can create a new
Customer object, create 5 new PhoneNumber objects, attach them to the
customer, then call the save() method on the Customer and it will recurse
through all attached objects, saving each of them).  Another thing I had
done halfway was support for querying objects (without using SQL).
Basically I had created different types of criteria that could be used, but
my support for criteria wasn't general enough.  IOW, if I didn't forsee that
you would want a particular type of criteria, then you couldn't use it.
Propel gets this right by supporting any arbitrary criteria using their
Criteria object approach (and I'm sure Metastorage has similiar
functionality).  If you can represent it using SQL, you can represent it
using Propel's Criteria.

My point is, I had implemented my own home grown ORM about 3-4 times, and
while each one was much better than the one that preceded it, I still wasn't
quite all the way towards a 100% general implementation.  That's when I
found Propel.  It got so many things right that I hadn't figured out how to
solve, as well as implementing things that I hadn't even considered yet.

Now, you could argue that going through all those iterations and refactoring
my own ORM helped me to improve my skills as a programmer, and you would be
right.  That's where I agree with you, somewhat. :)  However, I was many
many iterations away from improving my ORM to the point where it would be as
useful as Propel (and that's assuming it would ever be that useful).  The
guys who developed it (and I'm sure the same goes for Manuel and
Metastorage) concentrated on making the best general purpose ORM they could
make.  IOW their whole goal was to build an ORM, while my goal each time was
to develop one for the purposes of finishing whatever real project I
happened to be working on.  That meant they were closer to the problem, had
more experience with it, and were willing to do more to solve it more fully
and generally than I was.

Originally I intended only to look at the code they had created and learn
from it, using their ideas in my project.  I started that way for a few
days, but I realized that there was so much they had accounted for that I
didn't even think of that it would be better to simply use their tool rather
than trying to reinvent it.

I think it's important to point out, however, that I have learned 

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

2005-09-20 Thread Michael Sims
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...

--
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 Michael Sims
Rasmus Lerdorf wrote:
 Michael Sims wrote:
 When used as an expression, an assignment evaluates to whatever is
 on the right side of the assignment operator, not the left. 
 Example:  
[...]
 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);

Oops, sorry for posting misinformation, I was not aware of the above...  Thanks 
for the info.

--
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 Michael Sims
Jochem Maas wrote:
 Michael Sims wrote:
 So, as far as foo() knows:
 
 foo($a = 5);
 and
 foo(5);
 
 are exactly the same...
 
 I don't think they are, and you're examples don't prove it.
 Anyone care to come up with the proof. 

No, I was wrong, Rasmus corrected me.  That's my one allowed mistake for the 
day.  I promise to wait until tomorrow before making another one. ;)

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




RE: [PHP] Re: Suggestions for class design

2005-09-20 Thread Michael Sims
Murray @ PlanetThoughtful wrote:
 My post was not aimed at saying 'using packaged approaches to solve
 coding problems is bad', but to say 'the original poster is asking a
 fundamental learning question, so a packaged approach will possibly,
 maybe even probably, hamper his development as a programmer at this
 point.'
[...]

Gotcha.  Makes sense; thanks for explaining...

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



RE: [PHP] Suggestions for class design

2005-09-19 Thread Michael Sims
Chris W. Parker wrote:
 Let's take for example a class called 'Customer' that (obviously)
 manipulates customers in the database. Here is a very basic Customer
 class. (Data validation and the like are left out for brevity.)
[snip]
 Where I get tripped up is when I realize I'll need to at some point
 get more than one customer at a time and thus I want to add a method
 called 'get_customers()'.

 Since an object should be a single instance of something (e.g. ONE
 customer) how do I justify adding the method 'get_customers()'? Or
 better yer, how do I properly add a method like that? (A method where
 instead of using a SQL statement to return ONE customer's data I
 instead return a record set with more than one customer.)
[snip]

Basically you're implementing DAO's (Data Access Objects), similar to what an 
ORM
(Object Relational Mapper) tool would do for you.  There are lots of different
approaches for implementing DAO's, but personally I prefer to use a DAO class 
that
represents one entity in my database (in your example, the Customer), and then 
have
another separate class which is responsible for data operations on my DAO (the 
peer
class).  (This is the approach that many existing ORM tools use, both in the 
PHP and
Java worlds.)  In other words, Customer is only used to access the data that has
been retrieved, but Customer itself doesn't have any methods for retrieving,
updating, deleting, or saving.  The CustomerPeer class handles all the data
operations on Customer.  If you want a particular Customer instance, you ask the
peer to retrieve it for you, and it returns the appropriate object.  If you 
want to
save changes to a Customer, you retrieve the right instance, set its attributes,
then give it back to the peer class which handles the database interaction.  
So, the
Customer class is completely ignorant of the database, and is only concerned 
with
giving you access to the data that is related to that Customer (and any other 
app
specific methods that it makes since for the Customer class to handle).

The advantage to using this approach is that you can easily have your peer class
return an array of Customer objects, each one representing only one customer.

Chris W. Parker wrote:
 Well, yes I think it does, but what I'm missing is how this new object
 interacts with the original one if it does at all. And what would I
 call it? 'Multiple_Customers'? Or.. perhaps just 'Customers'! :)

 Do I extend the Customer class or is it a stand alone class?

As stated, I wouldn't recommend creating a new class to hold the Customers.  
Just
use a normal PHP array of Customer objects.

In your spare time, take a look at Propel (http://propel.phpdb.org/), an ORM for
PHP5.  I wouldn't suggest trying to introduce something like this in the middle 
of
an existing project, but consider toying around with it for a future project.  I
used this for my last application with great success.  It used 20 DAO's, 
similar to
your Customer object, and Propel saved me a lot of tedious work in implementing 
all
of the data-related methods+getters/setters for these 20 objects.  If you have 
any
questions about it feel free to drop me a line or check out the Propel mailing 
list
which is very helpful.

HTH...

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



RE: [PHP] PEAR and MSSQL

2005-08-17 Thread Michael Sims
Chris Boget wrote:
 We are using PEAR as our database abstraction layer for connectivity
 to MSSQL.  It seems that, for some inexplicable reason, that our code
 is losing it's connection to the sql server.

I've had similar problems in the past, only in my situation it was connecting 
from a
Linux machine to MSSQL via FreeTDS.  However, from your description it seems 
like
our problems MIGHT have the same root cause.  I would suggest that you try the
following:

(1) Disable persistent connections.  This is just my own personal experience, 
but
I've never been able to get PHP's persistent connection mechanism to work 
reliably,
at least with MSSQL.  My experience is that it causes intermittent problems 
which
all seem to indicate that the connections eventually become unreliable or 
unusable,
and the persistent connection code doesn't seem to be able to recover from this
situation gracefully.  At least with normal connections you don't have to worry
about a problem with one request persisting to the next.

(2) MSSQL Server seems to have a problem with applications that open many
connections in rapid succession.  Disabling persistent connections will 
exacerbate
this problem, as a connection will be opened for each request.  It seems these
problems are caused, at least in part, by SQL server limiting the number of 
incoming
connections it will queue up.  This behavior can be controlled by adjusting 
MSSQL's
WinsockListenBacklog setting.  The default setting is 5, which means that the 
server
will queue up a maximum of 5 incoming connections.  The server will then reset 
any
new connections that come in as long as the queue is full.  In my situation, I
adjusted this value to 10, and this had a HUGE affect.  We still have problems 
from
time to time, but now they are very rare and they could probably be eliminated
completely by adjusting this number even higher, I just haven't gotten around to
doing that yet.

For more information on how to adjust the WinsockListenBacklog setting, see 
these MS
knowledgebase articles:

http://support.microsoft.com/default.aspx?kbid=328476
http://support.microsoft.com/kb/154628/EN-US/

The following PHP bug reports seem to be related to this:

http://bugs.php.net/bug.php?id=19541
http://bugs.php.net/bug.php?id=29074

Try disabling persistent connections and adjusting the WinsockListenBacklog to 
10
and see what results you get.

HTH

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



RE: [PHP] REGEX for query

2005-08-11 Thread Michael Sims
Jay Blanchard wrote:
 [snip]
 Assuming unix, I'd do the following from the root of the application
 to get a list
 of files that contain queries:

 $ egrep =[:space:]*\.*\b(SELECT|INSERT|UPDATE)\b * -ril
 ...

 Anyway, that's how I'd do it.  Hope you got something out of this...
 :) [/snip]

 That is a good start, now all I need to do is get the whole query(s)

I guess I misunderstood your goal.  You said before that you needed to LOCATE 
the
queries, which the above will do (if certain assumptions are true).  What 
exactly
are you wanting to accomplish?  Are you trying to write a script that will 
extract
the entire query from a set of PHP files?

If so, and given this:

$variableName = INSERT INTO bar (foo) ;
$variableName .= VALUES ('.$foo.') ;

Would you expect:
INSERT INTO bar (foo) VALUES ('')

or something else?

At any rate, if you are trying to automatically extract entire queries, I'd say
that's pretty tricky, unless your code uses very strict idioms for defining 
queries
that it doesn't stray from.  For example, if the code always do this:

$query = select .;
$query .= from .;
$query .= where ;

That's one thing, but if it sometimes does this:

$query = select .
 from ..
 where .;

Then that's something entirely different.

Assuming the first, you could perhaps use a two-pass approach where you first go
through a file and find the beginning of a query assignment (using a regex like 
the
one above), then extract the variable name and line number.  Then on a second 
pass
start from each line number you saved and process line number + N lines (where 
N is
the largest number of lines the code normally takes to define a query, 
arbitrarily
chosen) and look for lines where the variable name is followed by an assignment
operator (= or .=).  Then use a regex on those lines to extract everything 
between
quotes (hopefully just double quotes, unless the code tends to switch between 
double
and single).  But then you run into problems when your N is too large and the 
end of
one chunk overlaps into the beginning of the next.  I would imagine something 
like
this would take a lot of time to get right, and even then only be an 80% 
solution,
if that.

It seems to get this 100% right you'd have to have a full-fledged PHP parser, 
which
means hacking the parser that PHP itself uses.  Even hacking the PHP parser 
probably
wouldn't get you a 100% solution because the compile stage won't be 
enoughthere
is going to be code that may or may not be evaluated at runtime and I think it 
would
be impossible to know without actually running it.

So...if you absolutely have to have this done programmatically (as opposed to 
just
locating the beginning of the queries and manually extracting them) then I 
would say
good luck to you. :)  Hopefully someone else has some ideas...

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



RE: [PHP] REGEX for query

2005-08-10 Thread Michael Sims
Jay Blanchard wrote:
 I have a rather interesting issue. I need to locate every query in
 every PHP application we have for an integration project. I have
 started doing some research, but I wanted throw this out there as a
 little exercize because it is interesting.

 Several queries are written as
[...]
 How would you begin to get the queries using PHP? Regex? Other
 methods? I am working on isolating where the applications live right
 now, but I would be thrilled to read your opinions and methods.

Assuming unix, I'd do the following from the root of the application to get a 
list
of files that contain queries:

$ egrep =[:space:]*\.*\b(SELECT|INSERT|UPDATE)\b * -ril

That is assuming that you always assign a query to a variable before executing 
it,
and the select|insert|update is always on the same line as the assignment 
operator.
For example, the above would not catch:

$variableName =
  SELECT foo  ;

But if you're reasonably sure you don't do that anywhere then it might be 
enough.

I'm assuming that at some point you're going to want to update those queries, 
or the
code surrounding them.  I'd use a good editor that supports regex searches 
across
multiple files.  I'd suggest jEdit (www.jedit.org); it's quite powerful and 
free,
but your favorite editor may have similar functionality already.  My next step 
would
be to load all of the files that egrep found for me into jEdit, then do a regex
search across all buffers for a similar pattern (
=\s*.*\b(SELECT|INSERT|UPDATE)\b ).  jEdit also has a feature known as 
HyperSearch
which opens a dockable window that lists every occurrence by file and line 
number,
and allows you to jump from occurrence to occurence by clicking on each one.  
I'd
then hit each one and do the appropriate update (that is, assuming the update in
question isn't so simple that it can be done with a global search and replace).

Anyway, that's how I'd do it.  Hope you got something out of this... :)

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



RE: [PHP] parallel execution of php code?

2005-08-08 Thread Michael Sims
Martin van den Berg wrote:
 I have this piece of php-code which inserts data into a database.
 Before inserting it must verify if the data is unique. The php code
 looks something like:

 $query = SELECT id FROM mytable WHERE bla LIKE  . $x .;
 $rows = execute( $query )
 if ( $rows == 0 )
 {
/* some more processing */
   $query = INSERT INTO mytable .. etc etc
   execute( $query )
 }

 Now here is the problem: when the user enters the page, and directly
 refreshes the record is inserted twice Is is possible that both
 requests are processed simulatiounsly by the server (apache on linux)?
 And can I add something like a critical section or semaphore to
 overcome this problem.

The problem with the approach above is that a race condition exists between the
check for the existence of the row in question, and the insertion of that row.  
It's
possible that the two requests can come so close together that both of them 
execute
their selects before either do their inserts.  It's not very likely in the 
simplest
cases, but as the amount of traffic (or the number of users you have who like to
quickly click refresh) increases there is a greater chance that this race 
condition
will cause a problem.

In my opinion it's best to let your RDBMS handle this concurrency problem, since
it's best equipped to do that.  Ideally you would be using some sort of 
constraint
to prevent duplicate rows in your table...whether this is a primary key, unique
index, foreign key, etc.  Inserting a duplicate row should result in an error 
from
the database.  In that case you can trap for the error in your PHP code (using
functions like mysql_error()) and handle it appropriately (for example, 
displaying a
friendly error message, or simply ignoring the query).

Another approach would be to start a transaction with a high isolation level 
before
executing the select, but to me this is less desirable because depending on your
database system it may cause contention problems if the entire table has to be
locked.  Simply attempting the insert and catching the error should be much 
lighter,
assuming it's possible to create the appropriate constraint in your database.

HTH

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



RE: [PHP] String to Stream

2005-08-05 Thread Michael Sims
Eric Gorr wrote:
 Again, I would like to treat the string as a stream.

 One possible way to accomplish this would be to simply write the
 string to a temporary file, open the file with fopen and then use
 fscanf, fseek, etc. to process the text.

 However, I am assuming there is an easier way (i.e. a method without
 the file io overhead) to be able to treat the string as a stream.

If you're willing to go the lengths of writing out a temporary file and the 
overhead
is the only thing that is stopping you, AND you are running on Linux, consider 
using
a tmpfs volume (RAM-based) and write your temp files there.  That should almost
eliminate any overhead of writing the file out.  tmpfs is flexible, as it grows 
(up
to a maximum you can set) and shrinks as necessary, and can even have its 
contents
paged out to the swap file if they haven't been accessed in a while.  Assuming
you've got the RAM to spare, setting one up is as simple as creating a 
directory and
adding an entry to /etc/fstab.  I've used tmpfs volumes for similar things in 
the
past with great success.  FWIW...

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



RE: [PHP] DAO/VO Pattern Help

2005-07-13 Thread Michael Sims
Jed R. Brubaker wrote:
 So I am running into a problem that I could really use some direction
 on: DAO/VO works great with single tables, but I tend to make my
 database work for its existance, and joins ar eeverywhere. What I
 don't understand is how to approach DAO/VO when table joins are
 involved.

 Can anyone think of some good resources?

Take a look at Propel, an ORM tool for PHP that is based on Apache Torque (a 
Java
ORM).  It is a code-generation tool that requires PHP 5, and it may possibly be
overkill for what you are trying to do, but at the very least you could look at 
some
of the code it generates to get some ideas for your own approach.

http://propel.phpdb.org

There are other ORM/DAO type utilities for PHP available, but since Propel is 
the
only one I've used I'll leave it to others to mention alternative resources.

HTH

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



RE: [PHP] Find largest integer filename

2005-07-05 Thread Michael Sims
Richard Lynch wrote:
 Suppose I have a directory with a HUGE number of filenames, all of
 which happen to look like integers:
[...]
 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?
[...]
 Is there some nifty shell command I should just exec?...

How about this:

$output = exec(cd $myDirectory; ls -C -1 | sort -n -r | head -n1);

That's assuming your version of ls supports the -C (list entries by
column) and -1 (list one file per line) options.  Mine does (Debian stable)
but if you're using a different *nix it may not.

HTH...

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



RE: [PHP] Bug in look-behind assertions in PCRE patterns ?

2005-03-23 Thread Michael Sims
Ian Thurlbeck wrote:
 Dear All

 Is this a bug ?
[...]
 $line = '$res = $bar(ddd, dfdf);';
 if (preg_match(/(?!\$)(bar)/, $line, $matches)) {
  echo Should NOT match \$bar, but found: .$matches[1];
 }
 

 In the first preg_match() is correctly ignores the foobar
 function name. However the second preg_match() does NOT
 ignore the $bar as I expected.

This is a quoting issue.  Above you are using double quotes, which interpolates
embedded PHP variables.  Therefore if you want a literal $ inside a 
double-quoted
string you have to escape it, as you have done.  However, the $ character is 
ALSO
a preg metacharacter (matches end of line).  This means that you must also 
escape it
for the preg parser as well, so you need to escape it twice, by putting another
literal backslash behind it:

if (preg_match(/(?!\\\$)(bar)/, $line, $matches)) {

Either that or you can use single quotes instead of double quotes:

if (preg_match('/(?!\$)(bar)/', $line, $matches)) {

Either one will work.

HTH

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



RE: [PHP] Regex help

2005-01-29 Thread Michael Sims
[EMAIL PROTECTED] wrote:
 OK, this is off-topic like every other regex help post, but I know
 some of you enjoy these puzzles :)

This isn't an exam question, is it? ;)

 I need a validation regex that will pass a string. The string can
 be no longer than some maximum length, and it can contain any
 characters except two consecutive ampersands () anywhere in the
 string.

 I'm stumped - ideas?

Yup, use this perl regex:

/^(?:()(?!)|[^]){1,5}$/

Where 5 above is the maximum length of the string.  You can change this to
any positive value and the regex will still work.  Basically it says look
for 1 to 5 single characters where each either isn't an ampersand, or IS an
ampersand but isn't immediately followed by an ampersand.  The (?!) is a
zero-width negative look-ahead assertion which is like other assertions such
as \b that don't eat up the portions of the string that they match.

Sample code, tested:

$maxLen = 5;

$testStrings = array(
  'a',
  'g',
  'df',
  'adfdf',
  'adfsdfff',
  'ff',
  'dfds',
  'dsdf',
  'ddf',
  'dff'
);

foreach ($testStrings as $string) {
  if (preg_match(/^(?:()(?!)|[^]){1,$maxLen}$/, $string)) {
print $string matches.\n;
  } else {
print $string does not match.\n;
  }
}

Hope this helps you (pass your exam? ;) )

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



RE: [PHP] Regex help

2005-01-29 Thread Michael Sims
Bret Hughes wrote:
 On Sat, 2005-01-29 at 08:58, Michael Sims wrote:
 [EMAIL PROTECTED] wrote:
 I need a validation regex that will pass a string. The string can
 be no longer than some maximum length, and it can contain any
 characters except two consecutive ampersands () anywhere in the
 string.

 I'm stumped - ideas?

 Yup, use this perl regex:

 /^(?:()(?!)|[^]){1,5}$/

 Great explanation.  Thanks from one who has not had an exam for over
 ten years.

Thanks...I actually just realized that the parentheses around the first
ampersand are unnecessary (that was a leftover from a previous attempt), so
this is simpler and will work just as well:

/^(?:(?!)|[^]){1,5}$/

Or if you don't care about capturing portions of the match and then throwing
them away:

/^((?!)|[^]){1,5}$/

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



RE: [PHP] Is this a mysql_connect() bug?

2005-01-29 Thread Michael Sims
tom soyer wrote:
 Thanks for the error handling code. I think PHP still has a basic
 problem. If mysql sever connection times out because wrong username or
 password was used, then mysql_connect() should return FALSE.

It does, at least for me on PHP 4.3.10 connecting to a local MySQL 4.0.23
server on Debian.  It returns a boolean false, and a warning is triggered:

Warning: mysql_connect(): Access denied for user: '[EMAIL PROTECTED]' (Using
password: YES) in ...

If I give it a server name it cannot connect to (due to a firewall blocking
the connection, for example) it will hang for about 60 seconds then return
false, triggering a warning:

Warning: mysql_connect(): Can't connect to MySQL server on ...

I was going to suggest that you run a cli test script and trace the system
calls to see what's going on but then I saw that you're using Windows.  I'm
not sure if there is an strace/truss equivalent for it (anyone know)?

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



RE: [PHP] Re: Avoiding NOTICEs on Array References

2005-01-27 Thread Michael Sims
Burhan Khalid wrote:
 Michael Sims wrote:
 [EMAIL PROTECTED] wrote:

 If one must check the value and not just the existence of the
 checkbox entry, or for other uses, e.g. where a flag may or may not
 be present, one is saddled with clumsy constructs like:

if (($isset($array['index'])  ($array['index'] == 1)) ...

 I'm surprised that no one mentioned

 if (array_key_exists(index,$array)) { /* .. */ }

Because we're talking about avoiding clumsiness, and:

if (array_key_exists('index', $array)  $array['index'] == 1) ...

is MORE verbose (and arguably clumsier) than

if (isset($array['index'])  $array['index'] == 1) ...

which for the purposes of this discussion is equivalent.

(And yes, I realize that in the case of a checkbox the mere test for key
existence is sufficient, but I like to be consistent in these types of
constructs despite the input type...)

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



RE: [PHP] Re: Avoiding NOTICEs on Array References

2005-01-27 Thread Michael Sims
Jochem Maas wrote:
 Michael Sims wrote:
 On a controller page (the C in MVC) that handles form submissions
 I create an array which defines what form variables are available
 and their default values if not entered.  I then use array_merge()
 to combine that array with $_POST (or $_GET, as the case may be) and
[...]
 Its a good idea - although to make this example work I believe you
 would need to use array_merge_recursive() - which does what you mean
 ;-)

Yup, good catch. :)  Since I started using this method I haven't actually
had a form with more than one dimension of variables like that.  Now if I do
I'll be saved a bit of troubleshooting; thanks. :)

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



RE: [PHP] Re: Avoiding NOTICEs on Array References

2005-01-26 Thread Michael Sims
Jochem Maas wrote:
 [EMAIL PROTECTED] wrote:
 If one must check the value and not just the existence of the
 checkbox entry, or for other uses, e.g. where a flag may or may not
 be present, one is saddled with clumsy constructs like:

  if (($isset($array['index'])  ($array['index'] == 1)) ...


 okay, I get where your coming from - indeed nasty business
 them checkboxes.

Here's an approach that I like which I think cuts down on the clumsy
constructs.

On a controller page (the C in MVC) that handles form submissions I create
an array which defines what form variables are available and their default
values if not entered.  I then use array_merge() to combine that array with
$_POST (or $_GET, as the case may be) and the result is an array that
contains all of my form variables with each guaranteed to be set and contain
a sane default.  array_merge() works in such a way that values in the first
default array will only be replaced if they actually exist in $_POST, which
is what I want.  (Contrived) example:

$formVars = array_merge(array(
  'firstName' = '',
  'lastName'  = '',
  'contactMethod' = 'email',
  'flags' = array('one' = 0, 'two' = 0, 'three' = 0)
), $_POST);

The above handles the case where you have:
input type=checkbox name=flags[one] value=1
input type=checkbox name=flags[two] value=1
input type=checkbox name=flags[three] value=1

Now, I do:

if (!empty($_POST)) {

  if (trim($formVars['firstName']) == '') {
//complain that first name is required
  }

  if ($formVars['flags']['one']) {
//handle the case where the first checkbox is checked
  }

  ...

}

This way I can safely reference anything in $formVars under E_ALL without
throwing notices.  I think it's a lot cleaner than the constant
(!isset($_POST['var']) || $_POST['var'] == '') stuff...YMMV

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



RE: [PHP] Seemingly weird regex problem

2005-01-20 Thread Michael Sims
Tim Boring wrote:
 On Thu, 2005-01-20 at 13:41, Jason Wong wrote:
 I suspect what you want to be doing is something like this:

   switch (TRUE) {
 case ANY_EXPRESSION_THAT_EVALUATES_TO_TRUE:
 ...
   }

 Thanks for the suggestion, but I'm not sure that does what I'm looking
 for.  I really think the problem is with my regex, not necessarily
 with the way I've constructed my switch statement.

No, Jason is right.  Your problem IS in the switch statement.  You cannot use 
it the
way you are trying to and get the results you're expecting.  Each case 
expression is
evaluated with the switch expression just as if you compared them with the ==
operator.  In your case, you're comparing the return value of preg_match() 
against
the $line string.  This isn't what you want.

Here's what happens.  Say your $line contains the string AKRN.  Your regex 
pattern
matches only if the line begins with a non-word character.  A is definitely a 
word
character, so the pattern does not match.  preg_match returns an integer 
indicating
the number of matches, which in this case is 0.

To evaluate your case, PHP does the equivalent of:

if (AKRN... == 0)

which is actually TRUE.  From:

http://www.php.net/manual/en/language.types.string.php#language.types.string.convers
ion

If the string starts with valid numeric data, this will be the value used.
Otherwise, the value will be 0 (zero).

Since AKRN doesn't begin with valid numeric data, it is converted to 0 for the
purposes of the comparison.  Since 0 == 0 the case comparison evaluates to true.

When you switch it to begin with a number, PHP now uses that number.  Say you 
switch
it to 1AKRN.  PHP then will compare 1 == 0 which is false.

To accomplish what you want you'll have to change it to:

switch (true) {
  case ($total_counter = 5):
...
  case (preg_match(...):
...

etc. as Jason suggested.  Why don't you try it and see if it works?

HTH

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



RE: [PHP] strtotime time zone trouble

2005-01-18 Thread Michael Sims
Marcus Bointon wrote:
 Much of the point of using zone names rather than fixed numeric
 offsets is that it allows for correct daylight savings calculations
 (assuming that locale data is correct on the server).

 Let me rephrase the question - how can I get the current time in a
 named time zone using strtotime and without using a numeric offset?

This may not be the cleanest way to approach it, but this is what I use and it 
Works
For Me(TM):

$timeZoneMap = array(
  'EST5EDT' = 'Eastern Time',
  'CST6CDT' = 'Central Time',
  'MST7MDT' = 'Mountain Time',
  'PST8PDT' = 'Pacific Time'
);

$currentTime = time();
foreach ($timeZoneMap as $envVar = $timeZone) {
  putenv(TZ=$envVar);
  print The current time in $timeZone is ;
  print strftime('%m/%d/%Y %I:%M:%S %p %Z', $currentTime).\n;
}

HTH

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



RE: [PHP] Inconsistent behavior, same code, different server

2005-01-18 Thread Michael Sims
Rob Tanner wrote:
 Granting the possibility that I may have unintentionally defined the
 variables differently, what might cause them to be treated one way on
 my development system and another on the production server given that
 the php.ini file is the same on both systems?  Any clues?

Compare the output of phpinfo() on both systems.  The php.ini's may be the 
same, but
perhaps settings are being changed somewhere else...for example in the 
httpd.conf,
.htaccess file, or ini_set().  The phpinfo() output will show all current 
settings
regardless of where they came from.

Are both servers connecting to the same Sieve server?  If not, perhaps the issue
lies there...  Of course without seeing any of your code I'm just guessing 
about how
those variables you mentioned are getting their values

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



RE: [PHP] searching and sorting

2005-01-18 Thread Michael Sims
Richard Lynch wrote:
 Brian A. Anderson wrote:
[...]
 I am thinking of incrementally adding the resultant hits into two
 associative arrays with the link to the data and a calculated
 relevance value, and sorting this array by these relevences.
[...]
 One Axiom: Keep as much of the scoring/sorting in your SQL as
 possible -- That's what SQL engines are best at.

I suggest the original poster look into some of the full text indexing
capabilities of his SQL server.  A lot of these (for PostgreSQL and MySQL
anyway) will automatically return a relevance value and handle sorting based
on that.  As you said, that'll be a heck of a lot more efficient and easier
to implement that doing it in PHP.

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



RE: [PHP] question about a cron job

2005-01-17 Thread Michael Sims
 #this is only for testing a new cronjob, every minute
 * * * * * /usr/local/bin/php
 /www/r/rester/htdocs/phpList_cronjob/process_cronjob.php
 /www/r/rester/htdocs/phpList_cronjob/cron.log 21


 The new one doesn't seem to want to run until after 3:01 or 3:02.
 Shouldn't the
 sever just run it every minute?

Yes, it should.  Cron normally emails any output (including messages to stderr) 
to
the owner of the cron job.  In this case you have 21 at the end of your 
command
which should be 21.  On my machine executing a command with 21 results 
in:

-bash: syntax error near unexpected token `'

which might explain why your job isn't running.  If I setup a test job that 
looks
similar to yours, the above error output is emailed to me.

Jay Blanchard wrote:
 You have to specify each minute...

* * * * * is sufficient for that.  I've got a couple of jobs on a box here 
that
run every minute and that's the way they are entered in my crontab...

HTH

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



RE: [PHP] question about a cron job

2005-01-17 Thread Michael Sims
Erwin Kerk wrote:
 The CRON daemon only refreshes it's job list after a job in the
 current list is completed. Therefore, the CRON daemon won't notice the
 every-minute job until 3.01 pm.

I'm not sure I understand what you're saying above.  Can you provide a pointer 
to
documentation about this?  The man page for Vixie cron states in part:

Additionally, cron checks each minute to see if its spool directory's modtime 
(or
the modtime on /etc/crontab)  has changed,  and  if  it  has, cron will then 
examine
the modtime on all crontabs and reload those which have changed.  Thus cron 
need not
be restarted whenever a crontab file is modified.

Vixie cron, at least, refreshes it's job list anytime a crontab is changed, and
keeps that job list until the next change is made.  Jobs should run according to
their way they are scheduled, and shouldn't be affected by the order they are 
listed
in the crontab or when other jobs are completed.

Perhaps I'm not understanding what you're saying (if so, my apologies) or 
perhaps
you are using a different flavor of cron that behaves differently.  I really 
only
have experience with Vixie cron, but I thought they all pretty much behaved the 
same
way...

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



RE: [PHP] question about a cron job

2005-01-17 Thread Michael Sims
Jochem Maas wrote:
 Michael Sims wrote:
 Additionally, cron checks each minute to see if its spool
 directory's modtime (or the modtime on /etc/crontab)  has changed,
 and  if  it  has, cron will then examine the modtime on all crontabs
 and reload those which have changed.  Thus cron need not be
 restarted whenever a crontab file is modified.

 say you change the crontab (do a save) in minute 2:49pm, then the file
 will be checked and reloaded, by the time that thats complete it will
 be passed 3:00:00pm (or more precisely after the jobtrigger was run),
 maybe what was meant was; that the 'everyminute' job would therefore
 trigger for the first time when cron checks jobs on 3:01:00pm?

Oh, I see.  At any rate, once it starts running at 3:01 it should then run every
minute from that point forward until it's removed from the crontab.  I'm not 
sure
that the OP was getting that point.  (BTW, I think you meant 2:59pm unless 
you've
got some really slow transfer rates on your hard drives. :)

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



RE: [PHP] Help with encryption

2005-01-15 Thread Michael Sims
Greg Donald wrote:
 On Thu, 13 Jan 2005 13:53:30 -0800, Brian Dunning
 [EMAIL PROTECTED] wrote:
 Could anyone point me to a web page or other documentation that
 shows a SIMPLE example of encryption?
 
 I know absolutely nothing about encryption.  There are like 6 people
 in the entire world who know something about it, but sadly.. I'm not
 one of them.  Good luck in your quest.

Now, who was it that said you didn't have a sense of humor? :)

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



RE: [PHP] PHP5 FreeTDS

2005-01-13 Thread Michael Sims
Craig Donnelly wrote:
 On the page where I connect to the MSSQL server I get the following
 error:

 Warning: mssql_connect() [function.mssql-connect]: Unable to connect
 to server: 172.16.xx.xxx in
 /var/ftpusers/tarot/tarot/admin/sqltest.php on line 4

A couple of things to try:

(1) Try defining a TDSDUMP file before the connection attempt and see if it 
provides
any hints as to why it failed.  I normally do this via:

putenv(TDSDUMP=/tmp/tdsdump);

before the connection attempt.  Make sure to remove this after you're done 
testing,
this file can get very big very quickly.

(2) Install Sqsh (http://www.sqsh.org/) and see if you can connect with it.  If 
not,
it may give you more information on the connection failure than PHP does (just
guessing here)...

HTH

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



RE: [PHP] quicker arrays as func args?

2005-01-13 Thread Michael Sims
Justin French wrote:
 Pretty sure this can't be done, but thought I'd ask any way...
[...]
 foo(cat,dog,(a=1,b=2,c=3)); or
 foo(cat,dog,{a=1,b=2,c=3}); would be nice (Ruby has
 something like this), but I'm guessing it's not possible.

No, can't do that.  I'm used to stuff like that from Perl as well.  It has been
brought up a few times on the internals list (check the archives for named
parameters or something like that) but has met with resistance so I doubt we'll 
see
something like this anytime soon.

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



RE: [PHP] Identify which function called another

2005-01-12 Thread Michael Sims
Lars B. Jensen wrote:
 Is there any way, I from one function can identify which other
 function called it, without parameter passing the name manually ? 

You can get this information from debug_backtrace()...

http://www.php.net/manual/en/function.debug-backtrace.php

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



RE: [PHP] stdClass to array

2005-01-11 Thread Michael Sims
Cere Davis wrote:
 Hey folks,
 
 Does anyone know of a painless way to convert a stdClass object to an
 associative array in php?

Just cast it:

$arr = (array) $stdClassInstance;

 Also, I wonder, is there a way to flatten associative arrays in php?
 So say:
 $b=new array(s=S)
 $a=new array(a=A,b=$b)
 
 goes to:
  $z=flatten($a);
 z turns to:
  (a=A, b=$b, s=S);

array_merge()

http://www.php.net/manual/en/function.array-merge.php

HTH

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



RE: [PHP] Fatal error: Call to a member function on a non-object

2004-12-22 Thread Michael Sims
Tim Burgan wrote:
 Fatal error: Call to a member function on a non-object in
 c:\XXX\inc\dbConnOpen.php on line 17
[...]

 The file in question contains code that forms a connection to the
 database. I've used this EXACT same code on this same website for the
 last 8 months (both on localhost and web host) with no problem.. then
 when I upload the WHOLE site again.. it doesn't work.
[...]
$db_connection = new COM(ADODB.Connection) or die(Cannot start

These might be relevant:

http://bugs.php.net/bug.php?id=31159
http://marc.theaimsgroup.com/?l=php-devm=110375720614120w=2

Not sure though...I don't have any experience w/the COM extension.  Looks
like a 4.3.11 might be out soon to fix this and other issues.

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



RE: [PHP] Re: How to set register_globals=off in the script?

2004-12-21 Thread Michael Sims
Jason Barnett wrote:
 So I want to keep PHP register_globals=on in php.ini, but in local
 files set to off?

 How I can do this?

 You can change this, and other php.ini directives, with the PHP
 function ini_set

register_globals cannot be changed with ini_set().  It is of type 
PHP_INI_PERDIR
meaning that it can only be changed in the php.ini, .htaccess, or httpd.conf.  
See:

http://www.php.net/manual/en/function.ini-set.php

Personally I prefer to set register_globals=off in php.ini, then use an 
.htaccess
file to turn it on only for those applications that absolutely require it to
function.  That way new applications default to register_globals=off.  IOW, I 
prefer
to have to take specific action to open up potential security holes rather than
having to take specific action to close them.  YMMV...

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



RE: [PHP] Sort by string length...

2004-12-21 Thread Michael Sims
Russell P Jones wrote:
 Any idea how to sort an array by string length?

Use usort() in conjunction with a user defined function that compares the 
length of
both strings using strlen().  If brevity at the (possible) expense of clarity is
your thing, you can even use create_function() as your callback argument to 
usort()
to make this a one-liner.  Of course if that were your sort of thing you'd 
probably
be using perl instead of PHP. :)

HTH

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



RE: [PHP] File Locking during *other* file operations

2004-12-17 Thread Michael Sims
Gerard Samuel wrote:
 Im talking about file locking during deleting, and moving
 files.
 Is it possible to perform file locking for these file operations?

Yes, have your scripts attempt to lock a separate lock file before performing
deleting or moving operations.

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



RE: [PHP] Problem with loose typing

2004-12-17 Thread Michael Sims
Chris Boget wrote:
   function test() {
 static $i = 0;
 
 $i++;
 $retval = ( $i = 10 ) ? $i : '';
 
 return $retval;
 
   }
   while( $bob = test()) {
 echo $bob . 'br';
 
   }
 
 You would expect the while loop to go on forever just looking
 at the above code. 

I wouldn't, but apparently you do. :)

 However, what's happening is that when the
 empty string is getting returned due to $i being  10, the while
 loop is resolving FALSE when $bob is set to the value of the
 empty string.
 Is there any way that I can force this not to happen?  That the
 while loop resolves as FALSE only when the function actually
 returns a (boolean) FALSE value?

while ( ($bob = test()) !== false ) {
  echo $bob . 'br';
}

should do the trick.

HTH

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



RE: [PHP] Re: 4.3.10 breaking things? Back working after reverting to 4.3.9

2004-12-17 Thread Michael Sims
Ben wrote:
 Reverting back to 4.3.9 with the same build configuration options used
 in 4.3.10 has fixed the problems with the various scripts.

Do you use Zend Optimizer?

If so you should upgrade to the latest version:
http://bugs.php.net/bug.php?id=31134
http://bugs.php.net/bug.php?id=31108

I don't use it personally but I figured this might be your issue.

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



RE: [PHP] Spurious newlines when requesting empty php file

2004-12-11 Thread Michael Sims
Carl Michael Skog wrote:
 If I save the response of this command with lynx (lynx -dump
 http://www.formatemp.com/catalog/paynova-reply.php;  somefile),
 I will get three newlines.

Aha! I knew it. :)  See:

http://marc.theaimsgroup.com/?l=php-generalm=110272197009025w=2

Lynx adds the newlines.  Better to use Links instead for this sort of thing.

 If I request this file in a browser and scrutinize the response
 packet in a packet analyser, I see something fishy.

 After the usual header fields part are closed with the usual double
 \r\n sequence, a new header is added, consisting of the character
 0.
 This is the then closed with the double \r\n sequence.

Yes, I've noticed that too, using Ethereal to capture packets.  Try this
with a php file that produces output.  If you capture the packet you'll see
that the output is preceded by a hexidecimal number and followed by 0.
The first hex number is the number of characters in the output.  This does
not happen with plain HTML files, at least not on my test machine.

 Obviously, this is part of the data part of the package, and possibly
 becomes the three newlines I am observing.

No...that's Lynx's fault.

 What does this extra header value come from ?

Aha, just found it:

http://www.apps.ietf.org/rfc/rfc2616.html#sec-3.6.1

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



RE: [PHP] Spurious newlines when requesting empty php file

2004-12-10 Thread Michael Sims
Richard Lynch wrote:
 Carl Michael Skog wrote:
 I would have thought that the response from a empty php file would
 also be empty, but, to my surprise, they consist of 3 newlines !!!

 I just tried this with an empty PHP file, and got exactly what I
 expected.

 A valid response with no content at all.

 Please specify your software versions, and provide URLs and, as silly
 as this sounds, an ls -als empty.php so we can see your empty PHP
 file.

Maybe he's using lynx -dump url to test this.  Lynx adds several newlines 
to the
output.  However, Links does not:

$ touch empty.php
$ lynx -dump http://localhost/empty.php | od -c
000  \n  \n  \n
003
$ links -dump http://localhost/empty.php | od -c
000

Just to add to the guessing... :)

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



RE: [PHP] Multiple Inheritance

2004-12-10 Thread Michael Sims
Please note that I am specifically *not* weighing in on the OO vs.
procedural religious war, but only wanted to make a couple of small
comments. :)

Richard Lynch wrote:
 I spend a *LOT* more time, digging through endless class files, of
 what are essentially name-spaces of singleton objects trying to
 find the line of code some idiot typed that is doing the wrong thing,
 but starting from 'index.php' I have *NO* *IDEA* how it got in there.

debug_backtrace() is your friend.  I have a tiny little backtrace function
that I use that accepts a label and dumps the label and the output of
debug_backtrace() to the terminal that I am SSH'ed into (via a redirect to
/dev/pts/[0-9]+).  If I have a complicated class hierarchy, or a series of
library files that include other files, etc. then I add a line into the
function that is giving me trouble:

backtrace('one');

If I have two functions I want to check I just add it again, but make sure
my label is different:

backtrace('two');

Then I request the page and check my terminal screen to see how the PHP
parser made it to the offending section(s) of code.  I even array_reverse()
the array returned from debug_backtrace() so it starts with index.php and
works it's way down (I find this easier to follow).

 I end up having to grep source code just to find the damn thing.

A good editor would help here.  For example my editor of choice, jEdit
(www.jedit.org), allows you to search for a string (or a regex) across every
open file, and using its HyperSearch functionality shows an index of
filename and line number containing your search string that you can easily
click on to jump around.  Of course it only searches files that are already
open, and if you're dealing with a large number of files sometimes grep is
still necessary to narrow down which ones need to be opened, but it's still
an immense help to me.  I'm sure many other editors offer similar
functionality.

Just a couple of tangential thoughts...

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



RE: [PHP] null as function argumnent?

2004-12-08 Thread Michael Sims
Bas Jobsen wrote:
 Hi,
 
 I want to use a ?: statement. If not true de default function
 argument have to be used. How to do this
 
 ?
 function test($test='default')
 {
 echo $test;
 }
 test(($value==1)?'no default':null);
 
 
 What do i have to pass instead of null to get default print?

Try this:

function test($test = null) {
  if (is_null($test)) { $test = 'default'; }
  echo $test;
}

test(($value == 1) ? 'no default' : null);

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



RE: [PHP] Re: automatic responder

2004-11-26 Thread Michael Sims
Matthew Weier O'Phinney wrote:
 * Manuel Lemos [EMAIL PROTECTED]:
 On 11/26/2004 03:58 PM, Alessandro Rosa wrote:
 How about coding an automatic responder via PHP ?
 
 The most portable solution is to have a POP3 mailbox associated with
 the e-mail address to which the messages are received and use a POP3
 client to access and process the message replying to it if that is
 the case.
 
 or IMAP... or use something like procmail or maildrop to pipe an
 incoming message to a PHP script that then processes and responds to
 it (my preferred method).

Or if using sendmail alias an address to a php script:

username: |/usr/local/bin/your_script.php

I'm sure other MTA's support this as well...

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



RE: [PHP] Capturing phpinfo()

2004-11-23 Thread Michael Sims
John Holmes wrote:
 From: Ashley M. Kirchner [EMAIL PROTECTED]
 How can I stick phpinfo() at the bottom of a page in such a way
 that it doesn't display the data in the page, but instead creates a
 log file and dumps everything in there)  The log file should either
 be appended to every time, or if not, a unique one created every
 time (one per transaction.)  Is this even possible?

 Of course it's possible. Just fopen() a file at the end of the
 script, capture phpinfo() output with an output buffer (ob_start(),
 etc) and write it to the file. I can imagine the file getting very
 large very quick, though.

Yup...on my test server here the HTML output of phpinfo() is 40Kb.  The text
version is 15Kb.  Depending on how many hits per day a site gets that can
add up fast.

Not only that, but also assuming a web server is involved there could easily
be many concurrent slave processes active.  Therefore if the file's
integrity is to be maintained (assuming a single file) then flock() should
be used.

Alternatively, assuming Apache, one file per request could be created.  If
mod_unique_id is installed/active then $_SERVER['UNIQUE_ID'] will be
available and could be used as the filename, or the basis for the filename.

Of course I'm not sure I see the point of saving phpinfo() for each
request...a large portion of it will be identical for every request.  Those
portions that differ from request to request can be logged more efficiently
in other ways...for example, dumping the contents of $_SERVER.  Of course,
much of that information can be gleaned from the Apache logs...

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



RE: [PHP] VOTE TODAY

2004-11-02 Thread Michael Sims
John Nichel wrote:
 ApexEleven wrote:
 I can't wait for the replies...
 
 cat $you  /dev/null

Or the slightly more destructive variant:

cat /dev/null  $you

:)

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



RE: [PHP] An easier way? $_POST[] = $_SESSION[]

2004-11-01 Thread Michael Sims
Erich Kolb wrote:
 Is there an easier way to assign all post data from a form to session
 data?

 Eg.,

 $_SESSION['first_name'] = $_POST['first_name'];
 $_SESSION['last_name'] = $_POST['last_name'];

 $_SESSION['email'] = $_POST['email'];

You could do this:

$_SESSION = array_merge($_SESSION, $_POST);

Although it might be better to ensure that only known valid keys from $_POST are
making their way into $_SESSION, doing something like this:

$keys = array('first_name', 'last_name', 'email');
foreach ($keys as $key) {
  if (isset($_POST[$key])) { $_SESSION[$key] = $_POST[$key]; }
}

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



RE: [PHP] Regex Lookbehind help

2004-10-26 Thread Michael Sims
Alex Hogan wrote:
 Hi All,

 I am trying to identify an email address in a page but I don't want to
 return the email if it's [EMAIL PROTECTED]

 Here's what I have;
 (\w[-._\w]*\w(?!webmaster)@\w[-._\w]*\w\.\w{2,3})

 It returns nothing, however when I take out the lookbehind section;
 ([EMAIL PROTECTED],3})
 it works fine, returning all email addresses in a page.

 What is wrong with my syntax?

I just tried this out and the first regex is actually working for me on php 4.3.8
(cli).  Can you post some code?

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



RE: [PHP] Is flock() necessary on a simple file append?

2004-10-26 Thread Michael Sims
Kevin Grigorenko wrote:
 Paul Fierro [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 According to this post, you do not need to use flock() if you open a
 file in append mode:

 http://marc.theaimsgroup.com/?l=php-generalm=105165806915109w=2

 That's exactly what I was looking for; however, I wonder whether that
 only applies to the one byte the poster speaks of, or as long as
 everyone is only appending.

This is my understanding, someone correct me if I'm wrong...

AFAIK, normally you need to lock even on appending.  Depending on how the OS buffers
disk writes (and how much data you are writing), it's possible that a portion of
process A's data will be written, then a portion of process B's, etc (interleaving).
You could end up with garbage data in your file if you don't ensure that the each
writer has exclusive write access.  In Rasmus's example you are only writing single
bytes, and the order that they are eventually written doesn't matter.  Each single
byte will be written as one operation (as opposed to being buffered into separate
writes if your data is larger) and it doesn't matter if process B gets to the file
before process A.  But if the amount of data you are writing is larger than what the
OS buffers then you could get interleaving data being written from concurrent
processes.

See:
http://groups.google.com/groups?selm=8c10kl%24frg%241%40rguxd.viasystems.com

That thread is from comp.lang.perl.misc, but what is discussed should apply to PHP
as well.

From your original post it looks like you aren't writing a lot of data per request,
so you probably won't have any problems with interleaving.  However, calling flock()
is fairly simple so I would if your data is important.

HTH

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



RE: [PHP] Regex Lookbehind help

2004-10-26 Thread Michael Sims
Alex Hogan wrote:
 I just tried this out and the first regex is actually working for me
 on php 4.3.8 (cli).  Can you post some code?

 At this point all I'm trying to do is print the array with the
 addresses.

 $file=readfile('mypathto/myfile.html');
 $patrn =
 (\w[-._\w]*\w(?!webmaster)@\w[-._\w]*\w\.\w{2,3});

 $addresses =preg_match($patrn,$file);

 print_r($addresses);

Check the documentation for preg_match()...it can't be used that way.  It returns
false or the number of matches, but not the matching text itself.  To get the
matches you have to supply the third parameter (matches).  Plus you'll probably want
to use preg_match_all() unless you only want to get the first match.

Also, I don't believe readfile() is what you want.  It looks like
file_get_contents() is more in line with what you are trying to do.

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



RE: [PHP] Mac OS X and Editor

2004-10-21 Thread Michael Sims
Philip Thompson wrote:
 I don't personally use Mac OS X, but let me throw in a
 recommendation for jEdit (www.jedit.org).  It's Java based, hence
[...]
 Just a side-comment: in general, OS X users enjoy/use Cocoa-based
 applications over Java-based. Cocoa provides the OS X Experience
 with the native aqua interface and other cool features that Java
 cannot always supply. (Not intending to start a discussion... just
 informing those non-Mac users.)

It's also been my experience that Windows users prefer pure Win32-based applications
over Java-based ones as well.  However, IMHO jEdit is so flexible and powerful, and
so completely out-classes every other *free* Windows based IDE I have used, that I'm
willing to put up with whatever headaches using a Java based program imposes (which
isn't much if you have a reasonably fast machine).  And it is possible on Windows to
configure jEdit so that it's look and feel is very much native Win32.  I'm not sure
if this is possible on OS X or not, but I'd be surprised if it weren't.

Also, this may not be an advantage for the average joe, but for me the
cross-platform capability that Java brings is a major advantage.  I'm a Windows user
now, but eventually I plan to switch to OS X (once I have the cash).  I like the
fact that I can use my favorite IDE, including all the plugins/customizations/macros
that I've built up over the last year or so, on OS X or Linux with a minimum of
hassle.

As usual, this is all IMHO and YMMV... :)

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



RE: [PHP] Mac OS X and Editor

2004-10-20 Thread Michael Sims
Jonel Rienton wrote:
 Hi guys, I just like to ask those using Macs here as to what editor
 and/or IDE they are using for writing PHP codes.

I don't personally use Mac OS X, but let me throw in a recommendation for jEdit
(www.jedit.org).  It's Java based, hence cross-platform, and extremely powerful.  I
use it on Windows and couldn't live without it.  I have installed it on my friend's
iMac long enough to see that it works, but not long enough to know of any
platform-specific issues and/or gotchas.

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



RE: [PHP] proper method to do the following...

2004-10-06 Thread Michael Sims
Hugh Beaumont wrote:
 the following code outputs :

 Notice: Undefined index: exact in search.php on line 10

 code :

 if (!isset($_POST['exact'])) {   - line 10
   $_POST['exact'] == false;
 }

You have a typo in line 11.  I'm assuming you want to use the assignment operator
= instead of the equality operator ==.  The PHP parser seems to be incorrectly
attributing the error to line 10 when it should be on line 11.  If you change ==
to = your error will go away.  It took me a moment to catch it because of the
misleading error message.

HTH

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



RE: [PHP] Recursive Interpolation

2004-10-05 Thread Michael Sims
Chuck Wolber wrote:
 On Mon, 4 Oct 2004, Michael Sims wrote:
 What's ugly about it?  I saw your earlier post I was actually
 planning on responding and suggesting something exactly like you
 just came up with.

 The main problem (aside from performance, which you addressed) is
 that it does not handle corner cases such as when you want to use one
 of your variables within the text of the dispatch (escaping).

I think the answer to that is to use a token delimiter that is unlikely to ever
appear literally.  In my implementation I look for tokens that appear between ?: and
:?.  The token is only replaced if it appears in my data array.  The likelihood that
I'll need a literal word surrounded by my delimiters that is also an existing token
in my array is low enough to be negligible, IMHO.

 It is
 also not truly recursive.

Maybe I'm not fully understanding the problem, but I don't see where recursion
enters into it.  Do you want the interpolate() function to call itself again when it
comes across uninterpolated tokens within a token?  Even PHP's own double-quote
interpolation doesn't work like that.  In the string this is a $variable the
$variable has to have already been defined at the time the string is evaluated...IOW
you cannot delay interpolation even in pure PHP code without using eval().  Can you
explain what you mean by truly recursive and give an example where it might be
useful?

 From a hacker standpoint, it extends the base PHP tool set, rather
 than making use of existing tools (not necessarily a bad thing). IMHO
 a non-ugly version of this would allow you to use standard PHP
 variables in your dispatch and force PHP itself to re-interpret the
 variables. This is why I think an interpolate() function would have
 to be built in to the base PHP interpreter rather than be done with
 the language itself.

I can see a value in having such a function, even if I personally wouldn't use it to
solve the problem you have described.  At least with my current, possibly incorrect
understanding of it. :)

 Any
 developers on the list want to comment on a possible interpolate()
 function?

Most of the PHP devs don't read this list.  You could post to the internals list,
although as another poster has already pointed out, this has been discussed there
already:

http://marc.theaimsgroup.com/?l=php-devm=109397509903069w=2

The poster in that thread used eval() for this, which is another option if you
haven't already considered it.

 I toyed around with using preg_replace_callback() for this eariler,
 but the only problem with it is that you can't create a callback that
 accepts more than just one variable (the array of matches).  This
 means I couldn't get the equivalent of your $msg_variable passed to
 the callback, so I had to make it global in the callback function
 (yuk). If it weren't for that it'd be a perfect solution, because
 preg_replace_callback would only be called once and the function
 wouldn't need to iterate through all of $msg_variable. It's times
 like that that I miss Perl's more powerful variable scoping rules.
 Ah well...

 Definitely cleaner and even appears (at first glance) that it lends
 itself to being recursive a lot easier than mine. Could you solve the
 global problem by doing a $this.msg_variable sort of thing within the
 callback?

No.  You can use a method for the callback, but it has to be static, which means no
instance methods therefore you're still stuck with globals.  Here was my version,
FWIW (watch for wrapping):

function processTemplate($text) {
  return preg_replace_callback(
'/\?:(.*?):\?/',
  create_function(
'$matches',
'global $values; return isset($values[$matches[1]]) ? $values[$matches[1]] :
$matches[0];'
  ),
$text
  );
}

Having to use a global bothers me far more than calling preg_replace() multiple
times. YMMV.

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



RE: [PHP] Recursive Interpolation

2004-10-04 Thread Michael Sims
Chuck Wolber wrote:
 The method I've come up with in the meantime, I believe is much more
 effective than heredocs, but still an ugly hack:

 function interpolate ($text, $msg_variable) {
 $msg_key = '_FP_VAR_';

 foreach (array_keys($msg_variable) as $key) {
 $token = $msg_key.$key;
 $text = preg_replace(/$token/, $msg_variable[$key],
 $text); }

 return ($text);
 }

What's ugly about it?  I saw your earlier post I was actually planning on
responding and suggesting something exactly like you just came up with.  My
version had the $token surrounded by markers, such as

This is a ?:token:?

but that's the only difference.  I think it's fairly clean and logical.

The only problem I can see with this approach is that it's inefficient as
$msg_variable gets larger or the $text gets larger, since you're iterating
through every key of the former, even if the token isn't in $text, and you
run preg_replace() once for each token, but that shouldn't hurt you unless
you really have a heavy traffic site, IMHO.

I toyed around with using preg_replace_callback() for this eariler, but the
only problem with it is that you can't create a callback that accepts more
than just one variable (the array of matches).  This means I couldn't get
the equivalent of your $msg_variable passed to the callback, so I had to
make it global in the callback function (yuk).  If it weren't for that it'd
be a perfect solution, because preg_replace_callback would only be called
once and the function wouldn't need to iterate through all of $msg_variable.
It's times like that that I miss Perl's more powerful variable scoping
rules.  Ah well...

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



RE: [PHP] Regular Expression - highlighting

2004-10-03 Thread Michael Sims
Aidan Lister wrote:
 Hello list,

 I'm pretty terrible with regular expressions, I was wondering if
 someone would be able to help me with this
 http://paste.phpfi.com/31964

 The problem is detailed in the above link. Basically I need to match
 the contents of any HTML tag, except a link. I'm pretty sure a
 lookbehind set is needed in the center (%s) bit.

 Any suggestions would be appreciated, but it's not quite as simple as
 it sounds - if possible please make sure you run the above script and
 see if it PASSED.

So basically, you want to put a link around foo, only if it doesn't
already have one, right?

The problem with look-behind assertions is that they have to be fixed-width.
If you're certain of what kind of data you're going to be dealing with then
this may be sufficient.  For example, I came up with a regex that will PASS
your script but I doubt seriously that it'll be very useful to you as it
would be easy to break it by coming up with various test cases.  For your
single test case, however, this works:

/(?!a href=foo)(?!a href=)(foo)/

The problem is that HTML tags can be split across lines...they have have any
variable amount of whitespace within the tag...they can have other
attributes (class, id, onClick), etc.  Since look behind assertions have to
be fixed width it'd be impossible (IMHO) to come up with a single regex that
would match all cases, unless the input data was uniform.  For example,
stuff like

a   href = foo ID=id1 class=redlink
onClick=javascript:someFunction();foo/a

and its infinite variants could not be trapped for with a single regex since
you cannot have an infinite number of fixed width look-behind assertions.
If quantifying modifiers such as '*', '+', and '?' were allowed in
look-behind assertions it would be possible, but they aren't (see man
perlre).

If your data is coming from unknown sources you'll probably have to use a
full fledged HTML parser to pull out text that isn't already part of an a
tag.  I know there are several of these available for perl and I'm sure
there are for PHP too but I'm unaware of them.

Sorry if this isn't terribly helpful.  Maybe I'm overlooking something and
someone else will point out a simple way to accomplish what you're trying to
do...

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



RE: [PHP] successive imap_open calls result in failure

2004-10-01 Thread Michael Sims
[EMAIL PROTECTED] wrote:
 Quoting raditha dissanayake [EMAIL PROTECTED]:
 This probably means that your imap server is running under xinetd (or
 something similar) that has a rate limit or a limit on the number of
 connections from one client. You can find out how many connections
 are open with netstat and i think you will find it's reached the
 allowed limit.

 Cheers that does appear to be the problem, it runs under inetd and at
 the nowait argument it does not specify how many connections many be
 started within 60 seconds. Apparently its limited to 40 by default so
 this could explain why when searching 80 folders it craps out due to
 opening 80 connections without about 10 seconds.

 Guess I'll have to get the admins to increase the limit to something
 like 200-300 and look to see if there is any way for the php scripts
 to detect the problem and stop before hitting it.

If possible, use an IMAP proxy.  The proxy will keep a pool of connections open and
when your IMP scripts request a new IMAP connection the proxy will return an
already-open one if it exists (similar to persistant SQL connections).  This may
help reduce the frequency of the problem since fewer connections will open in a
given time frame.  Two imap proxies:

http://www.horde.org/imapproxy/
http://www.imapproxy.org/

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



RE: [PHP] List Etiquette

2004-09-21 Thread Michael Sims
Octavian Rasnita wrote:
 No, there is no way for customizing the headers Outlook Express use
 to put in the email messages.
 I wish there was, because I don't like them also...

Although I haven't used it personally, OE-QuoteFix may help:

http://home.in.tum.de/~jain/software/oe-quotefix/

I do have experience with Outlook-QuoteFix by the same author and it works well.

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



Re: [PHP] Re: imap_open() on windows extremely slow?

2004-09-08 Thread Michael Sims
Michael Wallner wrote:

 Well, so here comes /the oddity/
 
 connecting from debian to windows/exchange ~0.5 seconds
 connecting from debian to debian/courier ~0.2 (assumed to be somewhere at 0.x 
 seconds)
 connecting from windows to debian/courier ~5 seconds
 connecting from windows to windows/exchange ~0.5 seconds
 
 Half a second is what I'd expect and is acceptable, but
 5 seconds seems to be more serious than an oddity...

Anytime I see something like this, I suspect that the server (in this
case, Courier IMAP) is attempting an ident lookup on the client, or is
attempting a reverse DNS lookup.  I suspect the latter is more likely.
For kicks, try temporarily adding an entry for your windows client to
the /etc/hosts file on the Debian/Courier server.  If that fixes the
problem then I would look for ways to disable reverse DNS lookups in
Courier.  Just a thought...

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



RE: [PHP] Odd behaviour of non-existent keys?

2004-08-26 Thread Michael Sims
Geoff Caplan wrote:
 Michael Sims wrote:
 IMHO what you have described is a bug in PHP, and if I were you,
 I'd report it as such.  If it's not a bug it at least has a very
 high WTF factor.

 Problem with reporting is that I am using Debian Test and the current
 PHP version is too old to report. If someone with an current PHP
 version could replicate the problem, let me know and I will report it.
 Here is the code:
[snip]

I've replicated it in version 4.3.8, as well as five other previous versions
(I always keep my build directories around for a while on my development
server.)

Here's a suggestion so that you don't have to depend on other people to
reproduce it for you (and in case one of the PHP maintainers asks you to try
a snapshot):

Download the PHP tarball you want to test with (4.3.8 or snapshot or
whatever) and extract it in your home directory, then configure it and run
make.  Then create your test script as a CLI script and make the shebang
line:

#!/home/your-home-dir/php-version/sapi/cli/php

This allows you to test with whatever version you wish without having to
actually install it.  FWIW...

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



RE: Re[2]: [PHP] Odd behaviour of non-existent keys?

2004-08-25 Thread Michael Sims
Geoff Caplan wrote:
 I think you are probably right - but this behaviour causes problems.
 For example:

 $foo['one']['two'] = test-string ;

 // Evaluates to TRUE (not what's wanted!)
 isset( $foo['one']['two']['three'] ) ;

 I need a reliable way to test for the non-existence of a
 multi-dimensional key. Any ideas? I guess I could convert the keys
 into a string via a loop and compare that, but there must be a more
 elegant way, surely?

IMHO what you have described is a bug in PHP, and if I were you, I'd report it as
such.  If it's not a bug it at least has a very high WTF factor.  Having to use the
cumbersome:

is_array($foo['one']['two'])  array_key_exists('three', $foo['one']['two'])

instead of:

isset($foo['one']['two']['three'])

seems kinda silly to me.  I doubt that this is the intended behavior.

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



RE: [PHP] RE: [SPAM] Re: [PHP] Sessions vs. IE security

2004-08-24 Thread Michael Sims
Stanislav Kuhn wrote:
 Thanks  for help. I have set up p3p policy to my site.. I passed it
 trouth validator and IE can find privacy policy but it still doesn't
 allow me cookies... I can't find information what exactly to specify
 in privacy policy IE allows me third party cookies...
 Does somebody idea?

This archived post may help:

http://marc.theaimsgroup.com/?l=php-generalm=108879240230567w=2

HTH

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



RE: [PHP] OO Theory Question

2004-08-17 Thread Michael Sims
Jed R. Brubaker wrote:
 Consider the following: I have a login class that is instantiated at
 the top of every page. It can log you in, check to see if you are
 logged in, etc. This class has an assortment of class variables such
 as userID, userType, etc.
[...]
 A solution is to set all of these variables into $_SESSION, but the
 appeal of classes is that I might be able to maintain all of my
 information in a related location, and not in the session.

One possible solution: use a factory method to instantiate your object, and have
this factory method return a cached session object if it exists, or a brand new one
if it doesn't.  This allows you to abstract the session from the way you use the
object, so if you decide to put this data somewhere else later you only need to
alter your factory method.  Example:

function factory() {

  @session_start();

  /* Create new Login object and cache it if one doesn't already exist */
  if (!isset($_SESSION['LoginObj'])) {
$_SESSION['LoginObj'] = new Login();
  }

  return $_SESSION['LoginObj'];

}

Using the above approach you could instantiate your object like so:

$login = Login::factory();

Then your pages wouldn't have to concern themselves with whether or not the object
was cached, or where the data is cached.  I've used the above approach with PHP4
several times.  If you're using PHP5 you can drop the  notation as objects are
passed by reference by default.

I hope I understood what you were asking for...

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



RE: [PHP] Problem querying postgres

2004-08-13 Thread Michael Sims
Joshua Capy wrote:
 of PHPADMIN and try use pg_query() to do a select such as SELECT
 PersonID FROM person

 the string that is sent is select personid from person. Now this is
 a problem because in the data base the field PersonID is not the same
 case as in the select that is sent and I get the error

 Warning: pg_query(): Query failed: ERROR: column personid does not
 exist in /Users/jcapy2/Sites/Jesper/SyncPosgresToMbrMaxData.php on
 line 70

 If I change the field to all lower case in the database this does not
 happen.

Are you certain that the query is being sent in lowercase?  Have you echo()'ed the
query to the browser to verify that?  I believe in Postgres that you have to quote
any identifiers contain mixed case or spaces.  Try sending your query as

SELECT PersonID FROM person

and see if that makes a difference.  I wouldn't be surprised if phpAdmin quotes all
identifiers just to be safe...

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



RE: [PHP] PHP logic - Whats going on here?

2004-08-11 Thread Michael Sims
Kim Steinhaug wrote:
[snip]
 For some reason the above results in a blank mail, no $body at all,
 rest is fine. However, if I include a dummy for if all goes well :

if(!$mail-Send()) {
   echo $lang_error['mailer_error'] . br\n;
} else {
   // Why do I need this one???
}

 What I dont understand is why do I need the last else statement?

You shouldn't.

 Isnt
 the result of $mail-Send() completed if I only check for
 !$mail-Send()?

Yes.

 Maby it would be better to write like this :
if(!$mail-Send()) {
   echo $lang_error['mailer_error'] . br\n;
} else if ($mail-Send()){
   // Why do I need this one???
}

 The above would in my belief send two mails, atleast my logic tells
 me that.

I'm not familiary with phpMailer, or exactly how the Send method words, but the code
above would end up calling the Send method twice.  If the Send method does in fact
send (as its name suggests) then you probably don't want to call it twice when you
intend to send the message only once. :)

[snip]
 Hope someone understand what Im wondering about here, hehe.

In PHP (and every language that I've ever used...) an if statement's expression is
evaluated regardless of whether there is an else portion, or an elseif, etc.  For
example, suppose we have a function foo() that is evaluated primarily for its side
effects, but may return either true or false to indicate if the function was
successful.  This:

if (foo()) {
  print foo() was successful!\n;
}

is functionally equivalent to this:

if (foo()) {
  print foo() was successful!\n;
} else {

}

The null else clause should have no effect whatsoever on the execution of the
script.  In fact, the following code snippets are all functionally identical:

//Version one
foo();

//Version two
if (foo()) {

}

//Version three
if (!foo()) {

} else {

}

In all three cases foo() is evaluated just once.

Something else you should be aware of:  When the expression in the if statement is a
compound expression (it contains multiple expressions), then the PHP parser uses
lazy or short-circuit evaluation.  This means that the parser only evaluates the
portions of the expression that are necessary to calculate the result of the entire
expression.  An example:

if (foo()  bar()) {
  //Do stuff
}

In the above example, foo() is evaluated first.  If foo() returns false, bar() is
not evaluated at all.  The reason is that no matter what bar()'s return value is,
the entire expression can only be false.  Since the parser has already determined
the final result, it has no need to evaluate any further terms.  Similarly:

if (foo() || bar()) {
  //Do stuff
}

In this example, bar() will not be evaluated if foo() returns true, but will be if
foo() returns false.  These are obviously simple examples, but basically the parser
only evaluates the terms that are necessary and doesn't go any further.  This can be
used as a type of flow control to have certain functions/methods called only if
another returned true or false.  For example, the following two code snippets are
functionally identical:

//Version one
if (foo()) {
  bar();
}

//Version two
if (foo()  bar()) {

}

As far as your specific problem, I suspect that there are factors at play that you
are not aware of.  Either you have run across a bug in the PHP parser itself
(unlikely), or you are inadvertently making other changes when you add the else
clause.  I would suggest using basic debugging techniques to echo/print the contents
of the body string at various points to see what it contains.  You may need to drill
down into the actual source code for the Send() method to see what it things the
body string is.  If something is happening to this value this approach should reveal
where it's occuring.

HTH...

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



RE: [PHP] PHP logic - Whats going on here?

2004-08-11 Thread Michael Sims
Michael Sims wrote:
 string at various points to see what it contains.  You may need to
 drill down into the actual source code for the Send() method to see
 what it things the body string is.

Errr... s/things/thinks/

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



RE: [PHP] Re: Classes, instances and NULL

2004-07-29 Thread Michael Sims
Oliver Hitz wrote:
 Thank you. I know there is a `===' operator, but to me this doesn't
 make sense either.

   class A { }
   class B { var $x; }

 It is logical that an instance of `A' is not identical to null.
 However, why is an instance of `A' equal (`==' operator) to null, an
 instance of `B' not? Do objects automatically evaluate to their
 associative array representation? Is this intended behaviour?

There are four different types that PHP could be casting the object and null to that
would result in them being equal, namely boolean, integer, float, and array.  It's
definitely not casting them to string or object.  My guess is the behavior is not
intentional since the documentation for the NULL type says that a variable is
equal to null only if it has had the null constant assigned to it, it has not had
a value assigned to it at all, or it has been unset().  You'd probably get more
definitive answers on the internals list.  Personally I consider the behavior a bug,
so I'd probably file a bug report on it, although I wouldn't expect it to be given a
high priority. :)


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



RE: [PHP] help with regular expression

2004-07-29 Thread Michael Sims
Barbara Picci wrote:
 I've a script that must strip a string when it find the first word
 containing at least 4 characters; it must print the content of the
 string before that word, that word, a separator and the rest of the
 string.

 I've tried with ereg whit this script ([EMAIL PROTECTED] is the separator):

 ereg( '^([^ ]{4,})(.*)$', $testo, $matches);

 $contents = [EMAIL PROTECTED];

 but it is not the right script because if the strin($testo) is the
 thing is the script doesn't find nothing and doesn't print. For this
 example the right content of $contents must be:

 $contents = the [EMAIL PROTECTED];

 instead of nothing.

I'm more comfortable with the PCRE functions:

$string = the thing is;

if (preg_match('/^(.*?\S{4,})(\s*)(.*)$/', $string, $matches)) {
  $contents = $matches[1].'[EMAIL PROTECTED]'.$matches[3].\n;
  print_r($contents);
}

prints

the [EMAIL PROTECTED]

Your regex is anchoring its search for the first 4 character word to the beginning
of the string, which is probably not what you want.

I'm assuming from your description that you want whitespace that appears after the
first 4 character word to be replaced by the delimiter.  Also you didn't specify
what should happen if the four character word happens to appear at the end of the
string.  Also keep in mind that there are other word boundaries besides simply
whitespace, so you might want to use the \w, \W metacharaters instead of \s
and \S.  See perldoc perlre for more details...

HTH

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



RE: [PHP] - operator and :: (formal names?)

2004-07-26 Thread Michael Sims
Katie Marquez wrote:
 Hi!

 I did a search of the PHP manual for these:

 - and ::

 I know what they are used for, but what I don't know
 is what they are formally called.  Can someone tell me
 what they are called (short of using the symbol in the
 name)?

I don't know what PHP's official name for these operators are but in Perl the -
is called the infix arrow operator since it lies between its operands (the
instance variable and the attribute or method name).  I've seen the :: referred to
as the double-colon operator, but I don't know how offical that is either. :)

HTH

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



RE: [PHP] background=#

2004-07-22 Thread Michael Sims
Tobias Brasier wrote:
 I have recently noticed a problem with our code or our webserver
 (Apache) when I execute a .php file.  I have taken all php code out,
 but within an html td tag, I use background=#, which is used for
 older browsers such as Netscape 4.7 if you have a background color or
 image in a table (the background # completes it throughout the td).
 This isn't the case for IE or NS 6+, though.

 The problem is that when I run the page, the log files show that the
 page was accessed twice.  This is only the case if the file has a php
 extension.  This does not occur if the file is an html file,
 though.

That's very odd.  Here's a suggestion that may help you to track down what is
happening.  Install the latest version of Mozilla, and then install the
LiveHTTPHeaders plugin (http://livehttpheaders.mozdev.org/installation.html).
Restart the browser, then click Tools  Web Development  Live HTTP Headers, which
should open a capture window.  Now request the page that is exhibiting this
behavior, then look in the capture window to see the exact headers that were sent
from your browser to the server and vice versa.  If there is any redirecting or
meta-refreshing going on the headers should reveal that.  At least then you can see
if your browser is actually requesting the page twice or if it's simply being
processed twice on the server side.  If you need help interpreting the output then
throw it up on a web page and post a link, since the header capture for even a
single fairly simple request can sometimes be quite verbose.

HTH...

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



RE: [PHP] exec/system question..

2004-07-21 Thread Michael Sims
Justin Patrin wrote:
 On Wed, 21 Jul 2004 10:09:52 -0700, bruce [EMAIL PROTECTED]
 wrote:
 2) i could run the perl script, and have it somehow run in the
 background this would ba good, if there's a way to essentially
[...]
 AFAIK there's no way to do this. When the request ends (user hits
 stop, exit or die called) the process is ended. This includes
 children.

There are ways around that, though, at least if you're running unix:

exec('bash -c exec nohup setsid your_command  /dev/null 21 ');

I found this method in a user contributed note underneath the documentation for
exec() and it works rather well.  The exec call returns very quickly and the child
process continues to run even after the parent process dies.  The important part of
the above command is nohup which runs a command that ignores hangup signals.

 If you could set it off asynchronously, there would be no
 way of knowing when it ended as the process wouldn't have access to
 that session any more.

If the OP could reimplement his perl script in PHP it could be passed the session ID
as an argument.  The child process could then call session_id($argv[1]) before
calling session_start(), and finally update the session data to indicate its current
status.

If that's out of the question the perl script could update its status in a database
table as you suggested...

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



RE: [PHP] exec/system question..

2004-07-21 Thread Michael Sims
Michael Sims wrote:
 Justin Patrin wrote:
 On Wed, 21 Jul 2004 10:09:52 -0700, bruce [EMAIL PROTECTED]
 wrote:
 2) i could run the perl script, and have it somehow run in the
 background this would ba good, if there's a way to essentially
 [...]
 AFAIK there's no way to do this. When the request ends (user hits
 stop, exit or die called) the process is ended. This includes
 children.

 There are ways around that, though, at least if you're running unix:

 exec('bash -c exec nohup setsid your_command  /dev/null 21 ');

Sorry to followup to my own post, but I just did some quick testing and apparently
none of the above (nohup, setsid) is really necessary.  As long as the output of the
command is redirected somewhere and the  is used to start it in the background it
will continue to run even if the process that launched it exits or is killed.  I
tested this with the following (named 'test.php'):

---
#!/usr/local/bin/php
?

if (isset($argv[1])) {
  exec('./test.php  /dev/null ');
}

sleep(10);

exec('wall testing - ignore '.getmypid());
?
---

I opened two SSH sessions, ran the above script in one (using './test.php 1') then
immediately exited the SSH session.  The PHP processes (both of them) continued to
execute and I saw the wall output from both scripts in my other SSH session.  So
apparently the nohup setsid stuff is overkill...

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



RE: [PHP] exec/system question..

2004-07-21 Thread Michael Sims
bruce wrote:
 my attempt (below) never seemed to work properly...

 php -r 'exec(perl /home/test/college.pl /dev/null 21 );' 
 works, but doesn't return until the perl app completes...


 php -r 'exec(bash -c 'exec nohup perl /home/test/college.pl
 /dev/null 21 ');'  can't get this to work/return

In what you've got above you are passing /dev/null as an argument to perl script
instead of redirecting to it, since you're missing the ...so change it to:

php -r 'exec(bash -c 'exec nohup perl /home/test/college.pl /dev/null 21 ');'

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



RE: [PHP] exec/system question..

2004-07-21 Thread Michael Sims
Justin Patrin wrote:
 On Wed, 21 Jul 2004 13:55:37 -0500, Michael Sims
 [EMAIL PROTECTED] wrote:
 Sorry to followup to my own post, but I just did some quick testing
 and apparently none of the above (nohup, setsid) is really
 necessary.  As long as the output of the command is redirected
 somewhere and the  is used to start it in the background it will
 continue to run even if the process that launched it exits or is
 killed.  I tested this with the following (named 'test.php'):
[...]
 Did you try it from the web?

No, I didn't actually try it via an apache request without the nohup.  I should do
that...

 Just to be devil's advocate and be sure
 that, say, clicking Stop doesn't stop the background process. Also,
 does *killing* the  original script kill the child?

No.  I tried killing the script via kill and then kill -9, allowing the parent
script to exit normally BEFORE the child (by having the child sleep() longer than
the parent), and disconnnecting from the controlling tty before the process
finished.  In all of the above tests the child process lived on and exited normally.

It seems to me that the PHP interpreter intentionally ignores hangup signals when it
detects that it's output is not being sent to a terminal.  Of course, this is
getting a bit beyond my current understanding of processes, signals, etc. so I could
be completely full of it. :)

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



RE: [PHP] exec/system question..

2004-07-21 Thread Michael Sims
bruce wrote:
 michael...

 something strange is happening/or i'm missing something basic... but
 here's the sys response from your suggestion...

 [EMAIL PROTECTED] test]# php -r 'exec(bash -c 'exec nohup perl
 /home/test/college.pl /dev/null 21 ');'
 [3] 2566
 -bash: );: command not found

Sorry, you've got to either escape the embedded single quotes:

php -r 'exec(bash -c '\''exec nohup perl /home/test/college.pl /dev/null 21
'\'');'

or just use double quotes and escape the embedded double quotes:

php -r exec(\bash -c 'exec nohup perl /home/test/college.pl /dev/null 21
'\);

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



RE: [PHP] Performance issues and trees

2004-07-20 Thread Michael Sims
Sven Riedel wrote:
 letters 0 and 1. My tree-traversal algorithm looks like this:

 $bit_array = str_split( $bitstring );
 $tree_climber = $tree;  // assign tree-climber to the
 tree root

 // main loop
 while( !is_null( $bit = array_shift( $bit_array ) ) ) {
   $tree_climber = $tree_climber[$bit]; // going down...
   if( !is_array( $tree_climber ) ) {   // we reached a node
   process( $tree_climber );
   $tree_climber = $tree;// and back up to the root we go
   }
 }

 I'm seeing execution times in excess of 30 seconds for a few hundred
 (~ 200 - 300 ) tree-runs (with the tree in question being of average
 depth 5, translating to 1000 - 1500 assignments, which is way to slow
 to be practical. And the main holdup _is_ the tree-traversal, the sum
 of the process() functions is in the range of 0.3 seconds (measured
 with microtime(true) ).

Have you tried using a profiler on the code?  APD might prove useful:

http://pecl.php.net/package/apd

This can show you exactly how much execution time is being spent in each function of
your code, whether user-defined or built in, and can list average execution times
per function, etc.

Personally it's been several years since I've toyed with binary trees (my second
semester of Pascal grin) and I can't tell for sure what's going on in what little
code you posted.  For example, I can't tell by what you posted if the array_shift()
above is necessary.  If you merely need to traverse $bit_array without actually
modifying it then I suspect a simple foreach would be much faster, but I'm probably
missing something...

If you have the time and the inclination you may want to post a link to your actual
working code...

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



RE: [PHP] Re: using the mssql functions on a linux server

2004-07-14 Thread Michael Sims
Skippy wrote:
 Is this the only way around it?  Can I get to mssql without using
 the mssql extension?

 I don't think so. Plus, the entire setup is a bit complicated and you
 need FreeTDS as well as UnixODBC installed, plus some /etc
 configuration magic.

Why is UnixODBC necessary?  I've been using PHP and FreeTDS to connect to a MS SQL 7
server for the past 2+ years and I've never touched UnixODBC.  Is there something
I'm missing by not using UnixODBC as well?

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



RE: [PHP] php 4.3.7/5.0

2004-07-13 Thread Michael Sims
Josh Close wrote:
 $result = mssql_query($sql);
 $row = mssql_fetch_array($result);
 $var = $row[0];

 So it should be an int. And if it's copied into a function it
 shouldn't be changed.

 But doing

 if($var)

 doesn't seem to work after I upgraded versions. Which is making me
 think that they changed how that works.

 And using is_string() or is_int() is pointless 'cause it doesn't
 matter. I just want to know if the value != 0.

 The problem is, if 0 gets changed to 0 somewhere throughout. That's
 why I've always used if($var) because it's usually not cared what the
 type is, but it seems to now.

This sounds an awful lot like the problem I experienced with PHP's Sybase extension
after upgrading to PHP 4.3.4.  Is your query retrieving data from a bit field ('0'
or '1')?  If so, you might want to read this:

http://marc.theaimsgroup.com/?l=php-devm=108377430919818w=2

I never did get a response to it.  I've had it on my TODO list to open it as a bug
for the longest time, but I haven't had a chance to come up with minimal reproduce
code and I frankly haven't had the time to deal with it.  I managed to work around
the problem by maintaining a local patch to PHP to undo the change mentioned in my
post above.  Let me know if this is your issue and I can explain more and/or provide
my simple patch.

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



RE: [PHP] php 4.3.7/5.0

2004-07-13 Thread Michael Sims
Curt Zirzow wrote:
 * Thus wrote Josh Close:
 if($var)

 used to work for

 if($var != 0) or if($var != 0)

 but that doesn't seem to work since I upgrade. So I'm just going to
 do

 if((int)$var)

 I still think this is unnecessary

 if (0) { echo '0'; }
 if ()  { echo ''; }
 if (0)   { echo 0; }

 As I pointed out earlier, are still all the same; this behaviour
 hasn't changed.

I agree.  As I pointed out in my earlier message in this thread, based on
the description that the OP gave (and the fact that he's using
mssql_query()), I think he's getting bitten by the problems introduced by
the fix for bug #25777:

http://bugs.php.net/bug.php?id=25777

Basically PHP used to trim trailing spaces from data being returned via the
mssql and sybase extensions, and the fix for the above bug (in both
extensions) was to stop this trimming.  In my case this introduced a new
problem, because bit fields that contain simply '0' in the database come
back with trailing spaces.  While this:

$ php -r 'if (0) echo Yes\n;'

produces no output (because 0 == false) this does:

$ php -r 'if (0 ) echo Yes\n;'

because 0  != false.

I have a hunch that if the OP does a print_r() on their $var, it will be a
string that starts with zero and ends with one or more spaces.  Casting $var
to int will restore the original behavior, but this is only because (int) 0
 === 0 and 0 == false.  So basically the cast to int does fix the OP's
problem but not for the reasons he believes.

Of course, that's a complete guess based off incomplete information.  I
could be way off. :)

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



RE: [PHP] Client IP

2004-07-07 Thread Michael Sims
John W. Holmes wrote:
 IP adress not send ?!? And how server communicate with client ?

 A variety of ways. What I meant is that it's not sent in the browser's
 headers that it sends to the site, which is where getenv() and
 $_SERVER[] would snatch it from.

Correct me if I'm wrong, but shouldn't $_SERVER['REMOTE_ADDR'] always be set
if you're using Apache?  I've never experienced a case where it was not
available.  I'm no C guru, but from what I can tell by looking into the
source for PHP 4.3.7 and Apache 1.3.28 it looks like Apache makes this
variable available to PHP based on the information it stores internally
about the currently-open connection to the client (see Apache's
src/main/util_script.c, line 292).  Have you experienced a case with
Apache  PHP where this variable was not available?  Just curious...

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



RE: [PHP] PHP page memory usage

2004-07-06 Thread Michael Sims
Michael Gale wrote:
 Hello,
 
   Is there a way to monitor or test out how much CPU / memory a php
 page uses ? I would like to find out how intensive some of my scripts
 are. 

Don't know about CPU, but you can get memory usage with this function:

http://www.php.net/manual/en/function.memory-get-usage.php

Your PHP must be compiled with --enable-memory-limit for this to work...

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



RE: [PHP] Problem with session on first page loaded

2004-07-02 Thread Michael Sims
Jordi Canals wrote:
 the ISP changed a param in the PHP.INI, and they changed
 session.use_trans_sid setting it to 1.
[...]
 Now I should talk to the provider to not set this parameter to ON by
 default, because the security risk on it (As stated on the manuals).

If they allow you to use .htaccess files, you can create one at the root of
your application with the following:

php_flag session.use_trans_sid off

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



RE: [PHP] session id changing all the time on some pc's

2004-07-02 Thread Michael Sims
Zilvinas Saltys wrote:
 The problem is as i understand IE is not accepting the cookie. So the
 session id allways regenerates. Everything works fine with mozilla.
[...]
 The only thing i want to know is all the truth about IE (6?) and
 cookies :)

Could it be a problem with IE6 and P3P (http://www.w3.org/P3P/)?

This is just hearsay, but a friend of mine told me about a problem he was having
with IE6 and cookies in his application.  He had to send a P3P header before some
versions of IE would accept the cookie.  I've read that P3P only applies to
persistant cookies, but his was temporary and was still not working until he added
this:

header('P3P: CP=NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM');

I have no first hand experience with this myself, and I haven't done the proper
research to become familiar with it.  Make of this what you will. :)  More
information here:

http://www.computercops.biz/modules.php?name=Newsfile=printsid=837

HTH

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



RE: [PHP] flock(), fclose() and O/S buffering

2004-07-01 Thread Michael Sims
Andrew Hill wrote:
 $fp = fopen(/tmp/lock.txt, w+);
 if (flock($fp, LOCK_EX)) { // do an exclusive lock
fwrite($fp, $processName\n);
flock($fp, LOCK_UN); // release the lock
 } else {
echo Couldn't lock the file !;
 }
 fclose($fp);
[...]
 In this case, although process B is the second process to obtain a
 lock and write its process name to the file, it is the first process
 to close the file handle.

I've used flock() quite a bit in Perl, but not so much in PHP.  I'm almost
positive that they both use the same system calls so I think the behavior
(at least under unix) is the same.  In Perl, you do not have to release a
lock before closing the file...the lock is automatically released on close.
Newer versions of Perl automatically flush the disk buffers when releasing a
lock, but it's still widely recommended that you do NOT release a lock
before closing a file if you have written to it, precisely because of the
race condition you pointed out.

From:
http://www.tcp.com/~mink/CLAM/week8.html

...Locks will dissolve when the file is closed anyway (when your process
exits, if not before). If you unlock without closing, the buffer may not
have been flushed before another process tries to read the file. In that
case, the other process will get old data. There are ways around this, but
the easiest is to simply not use LOCK_UN on files you are really writing
to - simply close the files and release the locks that way...

Also:
http://groups.google.com/groups?selm=388373bd.890334%40news.skynet.be
http://groups.google.com/groups?selm=Pine.GSO.3.96.97030353.695N-10%
40kelly.teleport.com

Of course these all apply to Perl, but I believe they could be applied to
PHP as well.  I wonder if this should be considered a documentation problem
with the given examples.

 My suspicion is that the answer to the above question is no, and as a
 result, in order to be certain of correctly serialising the file
 locking and output process, it would be necessary to use a separate
 lockfile, which is opened and locked *before* the file to be written
 to is opened, written, and then closed, after which the lock on the
 lockfile can be released.

I think that you will still have to do this, however, not because of the
fclose() issue but because you are opening the file in write mode, which
truncates it.  If you were opening in append mode you would be good by just
not releasing the lock before the fclose(), but since the fopen() in write
mode truncates the file BEFORE the lock is requested, you're in trouble
without using a separate lock file.  There is a note in PHP's flock()
documentation about that:

Note:  Because flock() requires a file pointer, you may have to use a
special lock file to protect access to a file that you intend to truncate by
opening it in write mode (with a w or w+ argument to fopen()).

So, I'd still go with getting an exclusive lock on a separate lock file,
writing to my actual file, then releasing the lock on the separate lock
file...

HTH

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



RE: [PHP] Comparison Operator

2004-07-01 Thread Michael Sims
Gabe wrote:
 I was looking at the comparison operators page and noticed that these
 two operators were listed as PHP4 only.  Is that an error, or are
 they really not used in PHP5?  I don't want to use them if they're
 going to break when I upgrade.  And if they aren't included, then
 does something else replace their functionality?

 Operators in question:
 ===
 !==

The PHP 4 only means those operators did not exist in PHP version 3.  The
documentation should probably say PHP 4 or later only...

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



RE: [PHP] Help with array / list looping syntax

2004-06-29 Thread Michael Sims
Robb Kerr wrote:
 I need some help with a looping syntax. In english, a is used before
 words that begin with consonants - an is used before words that
 start with vowels.

You are probably already aware of this, but that isn't strictly correct.
The rule for deciding between a and an is based not on the presence of
consonants and vowels, but on the presence of consonant and vowel _sounds_.
Most of the time these are the same, but sometimes they are not, such as in
the phrases an honorable agreement or a useful idea.  This distinction
may not matter for your program, but I thought I'd mention it just in case
you hadn't considered it.

 I'm trying to create a loop that checks this state
 and inserts the correct word in the echo line. Below is the sloppy
 version of what I'm trying to do...
[...]
 There's got to a cleaner way to do this.

Here's my version:

if (preg_match('/^[aeiou]/i', $word)) {
  echo 'an';
} else {
  echo 'a';
}

Mine is probably the least efficient approach of all those given thus far
from a pure performance standpoint, since I'm incurring the overhead of the
regex engine for something that can be accomplished without it, but IMHO it
is so much easier on the eyes that it's worth it.  Of course others may
disagree. :)

HTH

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



RE: [PHP] Best external app from php

2004-06-29 Thread Michael Sims
C.F. Scheidecker Antunes wrote:
 Hello all,

 I need to have a web application to call an external app that needs to
 execute on the background. (It is an *NIX server)
[...]
 My question is this:

 Is it better to write the external app in PHP or Java?

Assuming that you (or the developer(s) if not you) are just as
familiar/comfortable developing in Java as they are PHP, I would think the
most important factor would be code reuse.  Is there now or will there ever
be a need to share business logic between this external application and the
web interface itself?  If the answer is yes, or it's even possible that the
answer MAY be yes, I would highly suggest that you code both the web
interface and the external application in the same language, so you can
reference any business logic classes/functions created for one in the other.

A while back I developed a program that consisted of a traditional web
interface and a standalone command line script that gathered data from my
database, formatted it, and emailed it to subscribers based on their
pre-selected criteria.  I used PHP for the web application but at the time I
decided that Perl was better suited for the command line script than PHP
was.  *BIG* mistake.  I ended up recoding a lot of already-developed
business logic for the command line script.  Now maintenance on this program
is a nightmare.  Anytime anything significant changes in the business logic
I have to basically implement the change twice.  You may want to keep this
in mind, since it will be difficult if not impossible to share logic/code
between a PHP web app and an external Java program.

 If I write in PHP then I have to have a way to make the PHP not bound
 to time limitations as the operation might take a while.

That's easily accomplished.  You can create a separate php-cli.ini file for
the standalone PHP binary and configure different limits for
max_execution_time and memory_limit.

 Which one would put a higher load to the processor, a PHP app or a
 Java one?
 Which one will take longer?

I'll leave these questions to someone else, as I have almost no Java
experience...

 Also, there might be more than 20 of these threads running on the
 server at the same time, hence my concern on which language the app
 should be writen.

Since these processes can be launched by the end user at will (from the
sound of your description), you may have a lot more than just 20 of them
running.  It's very difficult to predict how end users will (ab)use your
program.  Some people like to click refresh a lot, for example. :)
Depending on how many people have access to your application, you may want
to put a mechanism into place to impose a hard limit on the number of these
processes that can be active at any time, or you may open your server up to
an increased possibility of DoS attack.  Just a thought...

HTH

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



RE: [PHP] Construction

2004-06-27 Thread Michael Sims
Paul Bissex wrote:
 FWIW Python also requires child classes to call parent constructors
 manually. Not sure what the justification is for this design decision
 is, though, in either language.  Anybody?

Flexibility, I would guess.  With PHP's current behavior one can:

(1) Call the parent constructor first, before the subclass constructor does
its work.
(2) Call the parent constructor last, after the subclass constructor does
its work.
(3) Call the parent constructor in the middle...doing some work before, and
then some work after. :)
(3) Pass through all of the subclass constructor's arguments to the parent
constructor unaltered.
(4) Change or filter some of the arguments that get passed to the parent
constuctor.
(5) Choose not to call the parent constructor at all.
(6) Many other things that I'm sure I'm overlooking...

If PHP called the parent constructor for you automagically, then how would
you implement the above options?  PHP would have to choose one approach and
stick to it.  I like the current behavior much better.

Forgive me if this has been mentioned in this thread previously, but PHP
does call the parent class constructor automatically if the subclass has no
constuctor, which does make sense

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



RE: [PHP] Understanding behavior of 'directories below files'

2004-06-25 Thread Michael Sims
KEVIN ZEMBOWER wrote:
 If you go to this URL, you'll get a broken version of the main home
 page on our site: http://www.hcpartnership.org/index.php/search . We
 can't understand this, because 'index.php' is a file, not a
 directory. (The correct web page is just at
 http://www.hcpartnership.org/index.php.)

Hopefully someone with more experience than me will answer this, but I did some
research and thought I'd post my findings.

First of all, I tested this on one of my servers and the same thing happened.  I
requested an existing PHP file and appended another directory name after it, and got
the page I requested.  It was broken the same way your example is, because the
page used relative URI's for the src attribute of all the img tags, and the browser
believed it was in a different directory than it really was, and requested images
that did not exist.

The output of php_info() showed this additional information to be in the
$_SERVER['PATH_INFO'] variable.  After doing some research I discovered that
PATH_INFO is part of the CGI spec.  Web servers will make this additional
information available to the CGI script as an environment variable.  Further reading
indicated to me that Apache passes all of this information to a script handler and
the script handler decides what to do with it.  Apache 2.x provides a configuration
directive to force it to return a 404 when given a path like the above, but 1.x does
not.  I believe that you can disable this behavior in PHP by configuring it with
--disable-path-info-check.  I'd be interested to know if this does correct this.
I personally see it as a problem for people who aren't intending to use it and use
relative URI's for images.  Not that it would come up very often, but still...

More info:
http://www.php.net/manual/en/configure.php
http://httpd.apache.org/docs-2.0/en/mod/core.html#acceptpathinfo

HTH

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



RE: [PHP] Testing if cookies are enabled

2004-06-21 Thread Michael Sims
Martin Schneider wrote:
 I saw this on some pages and want to do the same:

 - On one page the user can login. Before that no cookie is set!

 - On the next page they set the cookie and show either the user data
 or a warning that the user has disabled cookies and should enable
 them.

 I wasn't able to set and text a cookie on the same page! How is it
 done?

Probably wasn't done on the same page.  Here's my guess at how these sites do that:

(1) User visits login page, no cookie is set.
(2) User enters username and password in the login page form, clicks the submit
button, and the login page form posts back to itself.
(3) The login page has logic at the top to check and see if the form has been
posted...if so it verifies the user's credentials, sets a cookie, and then redirects
to the first page of the application.
(4) The first page of the application (main menu or whatever) checks to see if a
cookie has been provided.  If not, it displays the warning that the user has
disabled cookies.

So, the app sets the cookie and then immediately redirects to the page that checks
the cookie.  To the end user it would appear that the cookie was set and checked in
the same page.  HTH...

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



RE: [PHP] sessions cookies

2004-06-19 Thread Michael Sims
Scott Taylor wrote:
 How exactly do sessions work?  I've heard that if cookies are disabled
 that a session will then pass it's variables in the url (through GET).
 Yet when I manually disable cookies none of my pages work (because the
 $_SESSION variables do not seem to be working).

The variables themselves aren't passed, only a session ID, and that is only
passed through GET/POST if transparent SID support is enabled (it is
disabled by default).  You can change the session.use_trans_sid setting in
your php.ini file or if your server supports .htaccess you can create one
and add php_flag session.use_trans_sid on to it.  For more information see
the manual: http://www.php.net/manual/en/ref.session.php

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



RE: [PHP] Odd behavior with unset, array indexes, and types

2004-06-18 Thread Michael Sims
Curt Zirzow wrote:
 To simplify things:

   $a[2] = '1';
   $k = (double)2;
   echo isset($a[$k]);
   unset($a[$k]);
   echo isset($a[$k]);
   echo  - expect 1\n;


 Result:
   11 - expect 1

Yeah, my version was just a wee bit verbose. :)

 It's the behavior that is specific to unset() that I'm puzzled about.

 The problem is, array hash's and indexes must be either integer or
 string as noted in the manual, so technically it really isn't a bug
 even though it appears to behave like one.

Yeah, I agree.  Personally, IMHO if there is a problem the problem is with
isset(), not unset().  IMHO isset($var[(double) 2]) should return false at
the least.  Ideally I think any attempt to use a double as an array index
should produce a warning (or notice), just like trying to use a resource or
object does (Illegal offset type).  Although if the error didn't mention
double specifically it'd probably confuse the heck out of people.

 I would have to agree that there does seem to be inconsistencies
 between isset and unset, So perhaps mabey submiting a Feature
 Request showing how close php seems to supporting (floats) as indexes.

Probably a good idea.

 or to make the above not look too silly:

   $k = (int) ceil(3/4);

That's what I ended up doing.  I lost a couple of hours and quite a bit of
hair first, though. :)

Thanks for the feedback...

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



RE: [PHP] php

2004-06-18 Thread Michael Sims
[EMAIL PROTECTED] wrote:
  will retrieving data from files have a problem like if 2 person
 access the same file at the same time and causing the data to crush?

If you're only going to be reading the file you should be fine.  Otherwise you've
got a bit of research to do.  Here's a starting point:

http://www.php.net/flock

Have fun. :)

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



[PHP] Odd behavior with unset, array indexes, and types

2004-06-17 Thread Michael Sims
Just noticed this today.  The following script:

quote
$a = 2;
$b = ceil(3 / 2);

if ($a == $b) {
  print \$a and \$b are the same.\n;
}

$foo[$a] = '2';

if (isset($foo[$b])) {
  print \$foo[\$b] is set.\n;
}

unset($foo[$b]);
print_r($foo);
/quote

Results in this output:

quote
$a and $b are the same.
$foo[$b] is set.
Array
(
[2] = 2
)
/quote

ceil() returns a variable of type double.  In the above script I expected $foo to
become an empty array after calling unset().  But it seems that unset() will not
remove an array element when you refer to its key using a double, although isset()
will return true when referenced the same way.  If I cast $b to either an int or a
string, the unset call works.  Am I just missing the portion of the manual that
documents this behavior, or is this a bug?  Just thought I'd see if anyone had run
across this before...TIA

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



RE: [PHP] Odd behavior with unset, array indexes, and types

2004-06-17 Thread Michael Sims
Thomas Goyne wrote:
 On Thu, 17 Jun 2004 16:52:32 -0500, Michael Sims
 [EMAIL PROTECTED] wrote:
 ceil() returns a variable of type double.  In the above script I
 expected $foo to become an empty array after calling unset().  But
 it seems that unset() will not remove an array element when you
 refer to its key using a double, although isset() will return true
 when referenced the same way.  If I cast $b to either an int or a
 string, the unset call works.  Am I just missing the portion of the
 manual that documents this behavior, or is this a bug?  Just thought
 I'd see if anyone had run across this before...TIA

 == does not check type in php.

Yes, I'm aware of that.  That's not what my post was about.

 However,
 array indexes  are type specific, so $a[2] != $a['2'].

That's incorrect (at least with PHP 4.3.7).  PHP will happily cast your array index
and compare it without regard to type in some cases, as a simple test illustrates:

quote
$a[2] = 1;
if ($a[2] == $a['2']) {
  print Arrays indexes are not type specific, at least not in all cases.\n;
}

if ($a[2] == $a[(double) 2]) {
  print Integers and doubles compare, even when using '=='.\n;
}

if (isset($a[(double) 2])) {
  print isset() doesn't have a problem casting the array index.\n;
}

unset($a[(double) 2]);
if (isset($a[2])) {
  print It appears that only unset() has a problem with this.\n;
}
/quote

generates:

quote
Arrays indexes are not type specific, at least not in all cases.
Integers and doubles compare, even when using '=='.
isset() doesn't have a problem casting the array index.
It appears that only unset() has a problem with this.
/quote

It's the behavior that is specific to unset() that I'm puzzled about.

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



  1   2   3   >