OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
php-general Digest 17 Jan 2005 22:50:35 -0000 Issue 3233

php-general-digest-helplists.php.net
Date: Mon Jan 17 2005 - 16:50:35 CST


php-general Digest 17 Jan 2005 22:50:35 -0000 Issue 3233

Topics (messages 206532 through 206592):

Re: php editor
        206532 by: Benjamin Edwards

Re: Javascript newsgroup
        206533 by: Jay Blanchard

Apache thread exploding in memory size
        206534 by: N.Z. Bear
        206541 by: Marek Kilimajer

Re: PHP5 silently throwing exceptions???
        206535 by: Jason Barnett
        206542 by: Gerard Samuel
        206549 by: Jason Barnett
        206561 by: Jochem Maas
        206562 by: Jason Barnett
        206564 by: Gerard Samuel
        206580 by: Gerard Samuel

Re: Obtaining the base dir of a file in a web server
        206536 by: Jason Barnett
        206540 by: Leif Gregory

question about a cron job
        206537 by: Al
        206539 by: Jay Blanchard
        206543 by: Al
        206544 by: Erwin Kerk
        206545 by: Michael Sims
        206547 by: Al
        206556 by: Jason Wong
        206559 by: Michael Sims
        206560 by: Bret Hughes
        206568 by: Al
        206570 by: Jochem Maas
        206572 by: Michael Sims
        206576 by: Jochem Maas
        206579 by: Al

Returned mail: Data format error
        206538 by: alan.akbkhome.com

Re: $_REQUEST or $_POST?
        206546 by: Chris Shiflett

PHP in MS-DOS
        206548 by: Shawn McKenzie
        206551 by: Jason Barnett
        206555 by: Shawn McKenzie
        206557 by: Adrian
        206558 by: Jason Barnett
        206565 by: Mike Smith
        206575 by: Michelle Konzack
        206577 by: Bret Hughes

Finding first/last occurrence of a substring
        206550 by: Vikram Vaswani
        206563 by: Jay Blanchard
        206566 by: Benjamin Edwards
        206569 by: Jochem Maas
        206573 by: Bret Hughes

$_POST array not being populated
        206552 by: Bennie Foreman
        206553 by: Jason Barnett
        206578 by: Jay Blanchard

Re: Persistance objects + importing
        206554 by: Jochem Maas

Javascript problem
        206567 by: Gregg Healy

Socket_connect producing errors that show no reason
        206571 by: Adam Hubscher

Re: which is best php editor?
        206574 by: Matthew Weier O'Phinney
        206585 by: Greg Donald
        206589 by: M Saleh EG

Re: use php to determine user OS
        206581 by: Graham Anderson

Re: Persistent PHP web application?
        206582 by: Xuefer Tinys
        206590 by: M Saleh EG

Trouble with Apache 2.0, PHP and MySQL
        206583 by: Phillip S. Baker
        206584 by: Marek Kilimajer
        206587 by: Greg Donald
        206592 by: Jason Barnett

Re: Date()
        206586 by: Steve Buehler

Mail Delivery (failure php-generallists.php.net)
        206588 by: eriksson.php.net

Re: Phonetic speller function
        206591 by: Dotan Cohen

Administrivia:

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

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

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

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

attached mail follows:


Or you could get phpeclipse for free which is a php IDE. It all depends on weather you are a web designer or a php developer. If you are both you will still want an IDE (Integrated Development Enviroment) and Probably a debugger (see my previous email about phped). If you can aford to throw your money around why dont you get Zend Studio and Dreamwever, or I can send you my paypal details...

>>> David Green <d.greencsl.gov.uk> 01/14/05 01:53pm >>>
I've been using Dreamweaver (currently MX) since I started writing PHP
and I would defintiely recommend it if you can get hold of it.

You can download a trial from
http://www.macromedia.com/cfusion/tdrc/index.cfm?product=dreamweaver

William Stokes wrote:

>Hello,
>
>I'm quite new with writing php code. I was considering of using some kind of
>php editor program to help with the syntax. Know any goog ones?
>
>Thanks
>-Will
>
>
>

--
------------------------------------------------------
David Green
Information Centre, Central Science Laboratory
Sand Hutton, York, YO41 1LZ

Phone: +44 (0)1904 462388 (GTN: 5129 2388)
Fax: +44 (0)1904 462111
E-Mail: d.greencsl.gov.uk
------------------------------------------------------
CSL email disclaimer: http://www.csl.gov.uk/email.htm

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

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

______________________________________________________________________
This email and any files transmitted with it are confidential. It is for the intended recipient only. If you have received the email in error please notify the author by replying to this email. If you are not the intended recipient, you must not disclose, distribute, copy, print, or rely on this email. Any views expressed by an individual within this email which do not constitute or record professional advice relating to the RNLI, do not necessarily reflect the views of the organisation.

Registered Charity Number 209603

attached mail follows:


[snip]
I need to find a good Javascript newsgroup.
[/snip]

Are you familiar with Google?

attached mail follows:


Folks:

I am experiencing a problem with httpd child processes suddenly
exploding in memory size and consuming all available memory. The
behavior is sudden, not gradual: within a few seconds or a minute the
process swells to several orders of magnitude larger than its usual
size.

Listed below is a ps aux; the first httpd is a 'normal' one, the second
is the problem child:

nobody 23166 0.0 0.1 17572 2148 ? S 16:06 0:00
/usr/local/apache/bin/httpd
nobody 23167 1.4 63.7 2245624 1315584 ? D 16:06 1:00
/usr/local/apache/bin/httpd

Generally only a small number of child processes display this behavior:
often just one at a time.

The system setup is Linux with Apache 1.3.33, PHP 4.3.10 and MySQL
4.0.22-standard. I am not running mod_perl.

The vast majority of traffic on the site is PHP scripts, some of which
access the MySQL backend. I strongly suspect a problem in one of the
scripts, but have not been able to identify specifically which one. I
added the '%P' variable to my Apache log file and am now able to
identify the specific requests that the Apache child process which
explodes was handling prior to the error, but thus far no pattern has
emerged (different scripts appear last each time). I suspect that the
last entry I see in the log is the last successful request, not the one
that causes the problem. (I am aware of log_forensic, which I learned
would provide log output of a request *before* processing, but my skills
are not sufficient to make me feel comfortable rebuilding my Apache
server to include it at this time).

I am working around the issue with a cron script that checks if a child
process has exploded and then restarts Apache if needed; this helps to
mask the issue but is obviously not a fix. I have set
max_requests_per_child to a non-zero value but it has had no effect;
based on my understanding this doesn't surprise me as this is not a
gradual leak but a case where the process goes wild in the middle of a
request).

I recognize that it is unlikely that this problem can be
diagnosed-at-a-distance, but would welcome suggestions on debugging
tools and techniques which might help me narrow down the problem area.
In particular: other than log_forensic, is there a way to truly see what
that child process was doing when it went rogue? And does this behavior
sound like that of a bad PHP script?

Additional details & log files (including lsof, strace, and /proc
output) can be found at this post on my blog:
http://www.truthlaidbear.com/archives/2005/01/15/latest_on_performance_i
ssues.php#001639

Any and all suggestions are appreciated; thanks...

N.Z. Bear
The Truth Laid Bear
http://www.truthlaidbear.com

attached mail follows:


N.Z. Bear wrote:
> Folks:
>
> I am experiencing a problem with httpd child processes suddenly
> exploding in memory size and consuming all available memory. The
> behavior is sudden, not gradual: within a few seconds or a minute the
> process swells to several orders of magnitude larger than its usual
> size.
>
> Listed below is a ps aux; the first httpd is a 'normal' one, the second
> is the problem child:
>
> nobody 23166 0.0 0.1 17572 2148 ? S 16:06 0:00
> /usr/local/apache/bin/httpd
> nobody 23167 1.4 63.7 2245624 1315584 ? D 16:06 1:00
> /usr/local/apache/bin/httpd
>
> Generally only a small number of child processes display this behavior:
> often just one at a time.
>
> The system setup is Linux with Apache 1.3.33, PHP 4.3.10 and MySQL
> 4.0.22-standard. I am not running mod_perl.
>
> The vast majority of traffic on the site is PHP scripts, some of which
> access the MySQL backend. I strongly suspect a problem in one of the
> scripts, but have not been able to identify specifically which one. I
> added the '%P' variable to my Apache log file and am now able to
> identify the specific requests that the Apache child process which
> explodes was handling prior to the error, but thus far no pattern has
> emerged (different scripts appear last each time). I suspect that the
> last entry I see in the log is the last successful request, not the one
> that causes the problem. (I am aware of log_forensic, which I learned
> would provide log output of a request *before* processing, but my skills
> are not sufficient to make me feel comfortable rebuilding my Apache
> server to include it at this time).
>
> I am working around the issue with a cron script that checks if a child
> process has exploded and then restarts Apache if needed; this helps to
> mask the issue but is obviously not a fix. I have set
> max_requests_per_child to a non-zero value but it has had no effect;
> based on my understanding this doesn't surprise me as this is not a
> gradual leak but a case where the process goes wild in the middle of a
> request).
>
> I recognize that it is unlikely that this problem can be
> diagnosed-at-a-distance, but would welcome suggestions on debugging
> tools and techniques which might help me narrow down the problem area.
> In particular: other than log_forensic, is there a way to truly see what
> that child process was doing when it went rogue? And does this behavior
> sound like that of a bad PHP script?
>
> Additional details & log files (including lsof, strace, and /proc
> output) can be found at this post on my blog:
> http://www.truthlaidbear.com/archives/2005/01/15/latest_on_performance_i
> ssues.php#001639
>
> Any and all suggestions are appreciated; thanks...

You can try to enable php memory limit.

You can also log http requests in php. Each request will create it's own
file in some log directory, log all necessary info, and then remove it
at the end of script run. This way the log directory should contain only
  running and crashed processes.

HTH

attached mail follows:


Gerard Samuel wrote:
> Im currently using php 5.0.3 on a dev box,
> trying to figure out how to correctly use
> exceptions in my code.

Exceptions can be "A Good Thing".

> Per chance, I was monitoring the __autoload() function,
> and Im noticing that calls are being made to
> exception classes that I've setup.
> But nothing is being actually thrown.

AFAIK you cannot throw an exception during the __autoload function. Or
at least that was the way it was for me when I tried it back in 5.0.0b2.
  The answer I got was something along the lines of "the executor would
have no idea where to return", but it made little sense to me and I
probably am remembering that wrong anyways. :)

> As I understand it, __autoload(), only gets called, if a class
> file hasn't been loaded for a class.

Correct.

> I know for a fact that all my exception classes are derived from
> php's Exception class.

This is definitely a good practice as there are some internal functions
for those classes that are VERY useful to your own Exceptions... and you
cannot get the same functionality without extending the base Exception
class.

> I've debugged it down to this ->
> //try
> //{
> $db->connect();
> //}
> //catch(databaseException $e)
> //{
> // throw $e;
> //}
>
> The ::connect() method is supposed to throw a databaseException if a
> connection cannot be made.
> In my tests, connections are made, and the exception is not thrown.
> But the try/catch block above, for some reason, tries to throw
> the databaseException (according to __autoload()).
> If I comment it out the try/catch block, __autoload()
> doesn't try to load the databaseException object.

Um, perhaps you have things a little mixed up? __autoload is only used
to get a definition for an unknown class; it doesn't actually do any
object instantiation. It's used for "just in time" loading of a class
definition if and only if the class / file hasn't already been included.

>
> I dont know if this is a bug in my code, as Im still new to exceptions.
> Im just checking to see if anyone else experienced anything like
> this before...
>
> Thanks

--
Teach a person to fish...

Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
PHP Manual: http://www.php.net/manual/en/index.php
php-general archives: http://marc.theaimsgroup.com/?l=php-general&w=2

attached mail follows:


Jason Barnett wrote:

> Gerard Samuel wrote:
>
>> Im currently using php 5.0.3 on a dev box,
>> trying to figure out how to correctly use
>> exceptions in my code.
>
>
> Exceptions can be "A Good Thing".
>
>> Per chance, I was monitoring the __autoload() function,
>> and Im noticing that calls are being made to
>> exception classes that I've setup.
>> But nothing is being actually thrown.
>
>
> AFAIK you cannot throw an exception during the __autoload function.
> Or at least that was the way it was for me when I tried it back in
> 5.0.0b2. The answer I got was something along the lines of "the
> executor would have no idea where to return", but it made little sense
> to me and I probably am remembering that wrong anyways. :)

Yes, I read about this, and tried that eval() hack in the user comments
of the man page,
but there is a gotcha with that hack (that I wont explain here), that
caused me to stop using it. But I was only monitoring the __autoload()
function, to get a better understanding
of how it works.

>
>> As I understand it, __autoload(), only gets called, if a class
>> file hasn't been loaded for a class.
>
>
> Correct.
>
>> I know for a fact that all my exception classes are derived from
>> php's Exception class.
>
>
> This is definitely a good practice as there are some internal
> functions for those classes that are VERY useful to your own
> Exceptions... and you cannot get the same functionality without
> extending the base Exception class.
>
>> I've debugged it down to this ->
>> //try
>> //{
>> $db->connect();
>> //}
>> //catch(databaseException $e)
>> //{
>> // throw $e;
>> //}
>>
>> The ::connect() method is supposed to throw a databaseException if a
>> connection cannot be made.
>> In my tests, connections are made, and the exception is not thrown.
>> But the try/catch block above, for some reason, tries to throw
>> the databaseException (according to __autoload()).
>> If I comment it out the try/catch block, __autoload()
>> doesn't try to load the databaseException object.
>
>
> Um, perhaps you have things a little mixed up? __autoload is only
> used to get a definition for an unknown class; it doesn't actually do
> any object instantiation. It's used for "just in time" loading of a
> class definition if and only if the class / file hasn't already been
> included.

While I understand what you mean, what my chain of thought was at the time,
is why was an exception being loaded "just in time", and not being thrown.
And I think I know why it was doing what it was doing in my case.
I may be wrong here, but the line ->
catch(databaseException $e)
is what is *initiating* an exception object if it doesn't exist.
My understanding at the time, of try/catch blocks was that it only
enters the *catch*
stage, if an exception was thrown.
But it seems in reality, the *catch* stage is actually part of normal
code execution path.
This seems to make sense. If true, it would clarify my understanding of
the
try/catch block, and why __autoload() is being called on.

>
>>
>> I dont know if this is a bug in my code, as Im still new to exceptions.
>> Im just checking to see if anyone else experienced anything like
>> this before...
>>
>> Thanks
>

attached mail follows:


Gerard Samuel wrote:
> Jason Barnett wrote:
>
>> Gerard Samuel wrote:
>>
>>> I've debugged it down to this ->
>>> //try
>>> //{
>>> $db->connect();
>>> //}
>>> //catch(databaseException $e)
>>> //{
>>> // throw $e;
>>> //}
>>>
>>> The ::connect() method is supposed to throw a databaseException if a
>>> connection cannot be made.
>>> In my tests, connections are made, and the exception is not thrown.
>>> But the try/catch block above, for some reason, tries to throw
>>> the databaseException (according to __autoload()).
>>> If I comment it out the try/catch block, __autoload()
>>> doesn't try to load the databaseException object.
>>
>>
>>
>> Um, perhaps you have things a little mixed up? __autoload is only
>> used to get a definition for an unknown class; it doesn't actually do
>> any object instantiation. It's used for "just in time" loading of a
>> class definition if and only if the class / file hasn't already been
>> included.
>
>
>
> While I understand what you mean, what my chain of thought was at the time,
> is why was an exception being loaded "just in time", and not being thrown.
> And I think I know why it was doing what it was doing in my case.
> I may be wrong here, but the line ->
> catch(databaseException $e)
> is what is *initiating* an exception object if it doesn't exist.

Ah, I get what you are saying now. I think you're closer with this
guess, but I believe the actual code execution is something along the
lines of:

0. Begin try { } block
1. Enter ::connect()
2. ::connect() fails and you throw the exception (exception would be
instantiated here, __autoload is used etc.)

OR

2a. ::connect() succeeds and normal code flow resumes
3. The catch() needs to see if there is an exception of type
databaseException being passed to it. But in order to perform this
check PHP needs the class definition. Hence __autoload for the
exception class could also be performed here.

What's the point of the difference between what you stated and what I
stated? The catch { } block will only be executed if it is given an
exception of type (insert type here). So it needs to check what type of
exception PHP might have passed to it, but the code in the catch { }
block *doesn't* get executed unless the exception is passed.

> My understanding at the time, of try/catch blocks was that it only
> enters the *catch*
> stage, if an exception was thrown.
> But it seems in reality, the *catch* stage is actually part of normal
> code execution path.
> This seems to make sense. If true, it would clarify my understanding of
> the
> try/catch block, and why __autoload() is being called on.
>

I haven't checked the source on this one so I can't guarantee that what
I've said above is true, but I believe it to be true. Someone correct
me if I'm wrong (wouldn't be the first time ;)

--
Teach a person to fish...

Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
PHP Manual: http://www.php.net/manual/en/index.php
php-general archives: http://marc.theaimsgroup.com/?l=php-general&w=2

attached mail follows:


Jason Barnett wrote:
> Gerard Samuel wrote:
>

...

>
> I haven't checked the source on this one so I can't guarantee that what
> I've said above is true, but I believe it to be true. Someone correct
> me if I'm wrong (wouldn't be the first time ;)

seems to me like you 'on the money'.

I just wanted to add that IMHO use of __autoload() is over rated (too
much magic is not alway a good thing) in the general case, i.e. use it
for specific types of classes like dataobject classes that are generated
on the fly - but don't use it as a catchall handler

If you are using Exception classes and other 'framework' type classes
then I would suggest that a set of require_once statements in a global
file will:

a, suffice
b, make things more managable (i.e. includes are explicit)

if there is a speed issue with not using __autoload() then it might
still be worth only implementing __autoload() for general/all cases if:

a, sqeezing out a few microseconds is _really_ needed
b, your client (if you have one!) is willing to compensate you for the
countless hours of code profiling and speedmeasuring required to
increase speed thru optimization ;-)

>
>
>

attached mail follows:


Jochem Maas wrote:
> Jason Barnett wrote:
>
>> Gerard Samuel wrote:
>>
>
> ....
>
>>
>> I haven't checked the source on this one so I can't guarantee that
>> what I've said above is true, but I believe it to be true. Someone
>> correct me if I'm wrong (wouldn't be the first time ;)
>
>
> seems to me like you 'on the money'.
>
> I just wanted to add that IMHO use of __autoload() is over rated (too
> much magic is not alway a good thing) in the general case, i.e. use it
> for specific types of classes like dataobject classes that are generated
> on the fly - but don't use it as a catchall handler

I haven't tested this, but you make a good point. I would guess this
advice to be particularly good if you are using one of the opcode
cachers out there (since they may / may not be able to cache code for
files included via __autoload).

--
Teach a person to fish...

Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
PHP Manual: http://www.php.net/manual/en/index.php
php-general archives: http://marc.theaimsgroup.com/?l=php-general&w=2

attached mail follows:


Jason Barnett wrote:

> Gerard Samuel wrote:
>
>> Jason Barnett wrote:
>>
>>> Gerard Samuel wrote:
>>>
>>>> I've debugged it down to this ->
>>>> //try
>>>> //{
>>>> $db->connect();
>>>> //}
>>>> //catch(databaseException $e)
>>>> //{
>>>> // throw $e;
>>>> //}
>>>>
>>>> The ::connect() method is supposed to throw a databaseException if
>>>> a connection cannot be made.
>>>> In my tests, connections are made, and the exception is not thrown.
>>>> But the try/catch block above, for some reason, tries to throw
>>>> the databaseException (according to __autoload()).
>>>> If I comment it out the try/catch block, __autoload()
>>>> doesn't try to load the databaseException object.
>>>
>>>
>>>
>>>
>>> Um, perhaps you have things a little mixed up? __autoload is only
>>> used to get a definition for an unknown class; it doesn't actually
>>> do any object instantiation. It's used for "just in time" loading
>>> of a class definition if and only if the class / file hasn't already
>>> been included.
>>
>>
>>
>>
>> While I understand what you mean, what my chain of thought was at the
>> time,
>> is why was an exception being loaded "just in time", and not being
>> thrown.
>> And I think I know why it was doing what it was doing in my case.
>> I may be wrong here, but the line ->
>> catch(databaseException $e)
>> is what is *initiating* an exception object if it doesn't exist.
>
>
> Ah, I get what you are saying now. I think you're closer with this
> guess, but I believe the actual code execution is something along the
> lines of:
>
> 0. Begin try { } block
> 1. Enter ::connect()
> 2. ::connect() fails and you throw the exception (exception would be
> instantiated here, __autoload is used etc.)
>
> OR
>
> 2a. ::connect() succeeds and normal code flow resumes
> 3. The catch() needs to see if there is an exception of type
> databaseException being passed to it. But in order to perform this
> check PHP needs the class definition. Hence __autoload for the
> exception class could also be performed here.

Best explaination yet. This was what I was trying to convey in my previous
reply. With this explaination, it makes total sense, as to what I was
experiencing
with __autoload().
I think we could kill this thread, unless someone wants to bash the theory,
and put us in a tail spin.. :)
Thanks

>
> What's the point of the difference between what you stated and what I
> stated? The catch { } block will only be executed if it is given an
> exception of type (insert type here). So it needs to check what type
> of exception PHP might have passed to it, but the code in the catch {
> } block *doesn't* get executed unless the exception is passed.
>
>> My understanding at the time, of try/catch blocks was that it only
>> enters the *catch*
>> stage, if an exception was thrown.
>> But it seems in reality, the *catch* stage is actually part of normal
>> code execution path.
>> This seems to make sense. If true, it would clarify my understanding
>> of the
>> try/catch block, and why __autoload() is being called on.
>>
>
> I haven't checked the source on this one so I can't guarantee that
> what I've said above is true, but I believe it to be true. Someone
> correct me if I'm wrong (wouldn't be the first time ;)
>
>
>

attached mail follows:


Jochem Maas wrote:

> Jason Barnett wrote:
>
>> Gerard Samuel wrote:
>>
>
> ...
>
>>
>> I haven't checked the source on this one so I can't guarantee that
>> what I've said above is true, but I believe it to be true. Someone
>> correct me if I'm wrong (wouldn't be the first time ;)
>
>
> seems to me like you 'on the money'.
>
> I just wanted to add that IMHO use of __autoload() is over rated (too
> much magic is not alway a good thing) in the general case, i.e. use it
> for specific types of classes like dataobject classes that are
> generated on the fly - but don't use it as a catchall handler

__autoload() *is* a bit quirky. And I agree its not a catchall handler.
So far its not too bad, but I'll see as time progresses.

>
> If you are using Exception classes and other 'framework' type classes
> then I would suggest that a set of require_once statements in a global
> file will:
>
> a, suffice
> b, make things more managable (i.e. includes are explicit)
>
> if there is a speed issue with not using __autoload() then it might
> still be worth only implementing __autoload() for general/all cases if:
>
> a, sqeezing out a few microseconds is _really_ needed
> b, your client (if you have one!) is willing to compensate you for the
> countless hours of code profiling and speedmeasuring required to
> increase speed thru optimization ;-)

attached mail follows:


Juan Antonio Garrido wrote:
> Hi everybody:
>
> I use this sentence ($htmlFile = $_SERVER['DOCUMENT_ROOT'] ) for obtaining the
> complete route of a file in my web server, but inserts a white space to
> final char and i need remove it. I use the trim function but it continue
> there. How can i remove it? Can it be anohter char?
>
When dealing with absolute file paths I find it helpful to use realpath()
http://www.php.net/manual/en/function.realpath.php

--
Teach a person to fish...

Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
PHP Manual: http://www.php.net/manual/en/index.php
php-general archives: http://marc.theaimsgroup.com/?l=php-general&w=2

attached mail follows:


Hello Juan,

Monday, January 17, 2005, 2:23:23 AM, you wrote:
JAG> I use this sentence ($htmlFile = $_SERVER['DOCUMENT_ROOT'] ) for
JAG> obtaining the complete route of a file in my web server, but
JAG>  inserts a white space to final char and i need remove it. I use
JAG> the trim function but it continue there. How can i remove it? Can
JAG> it be anohter char?

See if this does it.

$htmlFile = trim($_SERVER['DOCUMENT_ROOT']);

Cheers,
Leif Gregory

--
TB Lists Moderator (and fellow registered end-user)
PCWize Editor / ICQ 216395 / PGP Key ID 0x7CD4926F
Web Site <http://www.PCWize.com>

attached mail follows:


I've got a question about the following cronjob.

>
> #At 3:01 our time, run backups
> 1 0 * * * /usr/local/bin/php /www/r/rester/htdocs/auto_backup/back_em_up.php >/www/r/rester/htdocs/auto_backup/cron.log 2>&1
>
> #At 3:02 clean up sessions folder
> 2 0 * * * (find /www/r/rester/htdocs/sessions/ -name 'sess_*' -mtime +1 -delete)
>
> #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 2>>&1
>

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?

And, the every minute job doesn't add anything to its log file.

Apache on a virtual host. The 3:01 and 3:02 jobs have been running fine for
months.

Thanks

attached mail follows:


[snip]
I've got a question about the following cronjob.

>
> #At 3:01 our time, run backups
> 1 0 * * * /usr/local/bin/php
/www/r/rester/htdocs/auto_backup/back_em_up.php
>/www/r/rester/htdocs/auto_backup/cron.log 2>&1
>
> #At 3:02 clean up sessions folder
> 2 0 * * * (find /www/r/rester/htdocs/sessions/ -name 'sess_*' -mtime
+1 -delete)
>
> #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 2>>&1
>

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?
[/snip]

You have to specify each minute...

http://www.unixgeeks.org/security/newbie/unix/cron-1.html

attached mail follows:


Jay Blanchard wrote:

> [snip]
> I've got a question about the following cronjob.
>
>
>>#At 3:01 our time, run backups
>>1 0 * * * /usr/local/bin/php
>
> /www/r/rester/htdocs/auto_backup/back_em_up.php
>
>>/www/r/rester/htdocs/auto_backup/cron.log 2>&1
>>
>>#At 3:02 clean up sessions folder
>>2 0 * * * (find /www/r/rester/htdocs/sessions/ -name 'sess_*' -mtime
>
> +1 -delete)
>
>>#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 2>>&1
>>
>
> 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?
> [/snip]
>
> You have to specify each minute...
>
> http://www.unixgeeks.org/security/newbie/unix/cron-1.html

I thought the "*" in the minutes position meant to run the script for all
minutes, 0.... 59.

Am I wrong?

attached mail follows:


Al wrote:
> I've got a question about the following cronjob.
>
>>
>> #At 3:01 our time, run backups
>> 1 0 * * * /usr/local/bin/php
>> /www/r/rester/htdocs/auto_backup/back_em_up.php
>> >/www/r/rester/htdocs/auto_backup/cron.log 2>&1
>>
>> #At 3:02 clean up sessions folder
>> 2 0 * * * (find /www/r/rester/htdocs/sessions/ -name 'sess_*' -mtime
>> +1 -delete)
>>
>> #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 2>>&1
>>
>
> 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?
>
> And, the every minute job doesn't add anything to its log file.
>
> Apache on a virtual host. The 3:01 and 3:02 jobs have been running fine
> for months.
>
> Thanks
>

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.

Erwin

attached mail follows:


>> #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 2>>&1
>>
>
> 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 "2>>&1" at the end of your command
which should be "2>&1". On my machine executing a command with "2>>&1" 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

attached mail follows:


Erwin Kerk wrote:
> Al wrote:
>
>> I've got a question about the following cronjob.
>>
>>>
>>> #At 3:01 our time, run backups
>>> 1 0 * * * /usr/local/bin/php
>>> /www/r/rester/htdocs/auto_backup/back_em_up.php
>>> >/www/r/rester/htdocs/auto_backup/cron.log 2>&1
>>>
>>> #At 3:02 clean up sessions folder
>>> 2 0 * * * (find /www/r/rester/htdocs/sessions/ -name 'sess_*' -mtime
>>> +1 -delete)
>>>
>>> #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 2>>&1
>>>
>>
>> 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?
>>
>> And, the every minute job doesn't add anything to its log file.
>>
>> Apache on a virtual host. The 3:01 and 3:02 jobs have been running
>> fine for months.
>>
>> Thanks
>>
>
> 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.
>
> Erwin
Wow, that is a key point and makes sense. Boy, I read several refs about
cronjobs and not one of them mentioned this.

So, if I put my 1 minute job first in the list, all should be well?

Thanks......

attached mail follows:


On Monday 17 January 2005 23:19, Al wrote:
> Erwin Kerk wrote:
> > Al 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.

Not sure if I've misunderstood what Al is saying but, the cron daemon checks
all crontabs for updates *every* minute. So at the most, 2 minutes after
you've updated your crontab the changes will take effect.

> Wow, that is a key point and makes sense. Boy, I read several refs about
> cronjobs and not one of them mentioned this.
>
> So, if I put my 1 minute job first in the list, all should be well?

--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
New Year Resolution: Ignore top posted posts

attached mail follows:


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...

attached mail follows:


On Mon, 2005-01-17 at 09:01, Erwin Kerk wrote:
> Al wrote:
> > I've got a question about the following cronjob.
> >
> >>
> >> #At 3:01 our time, run backups
> >> 1 0 * * * /usr/local/bin/php
> >> /www/r/rester/htdocs/auto_backup/back_em_up.php
> >> >/www/r/rester/htdocs/auto_backup/cron.log 2>&1
> >>
> >> #At 3:02 clean up sessions folder
> >> 2 0 * * * (find /www/r/rester/htdocs/sessions/ -name 'sess_*' -mtime
> >> +1 -delete)
> >>
> >> #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 2>>&1
> >>
> >
> > 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?
> >
> > And, the every minute job doesn't add anything to its log file.
> >
> > Apache on a virtual host. The 3:01 and 3:02 jobs have been running fine
> > for months.
> >
> > Thanks
> >
>
> 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 am not sure I read that correctly. Are you saying that the job cannot
be running for the new crontab to be installed? If so, I could see that
althought I have never experienced it.

If you are saying that each job in the crontab must be run before the
new crontab is completed, then I believe you are in error. I have often
changed crontab entries to test how a job will operate in the cron
environment and never experienced any delay on the acceptance of the new
job even though I have hourly and daily jobs there.

Bret

attached mail follows:


Michael Sims wrote:
> 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...

What you said has been my experience in the past. But, it has been a long time
since I fiddled with a cron job, so I wasn't certain of my memory.

Here is my code; but it doesn't run. I can't tell if there is anything wrong
with my crontab or my virtual webhost is faulty.

> #this is only for testing a new cronjob, every minute. This job replaces its log and error files.
> * * * * * /usr/local/bin/php /www/r/rester/htdocs/phpList_cronjob/process_cronjob.php >/www/r/rester/cronjob_reports/phpList.log 2>/www/r/rester/cronjob_reports/phpList.err
>
> #At 3:01 our time, run backups. This job replaces its log and error files.
> 1 0 * * * /usr/local/bin/php /www/r/rester/htdocs/auto_backup/back_em_up.php >/www/r/rester/cronjob_reports/auto_backup.log 2>/www/r/rester/cronjob_reports/auto_backup.err

There is a "cronjob_reports" folder. I am assuming that the ">" will create the
   log and err files as needed.

Thanks....

attached mail follows:


Michael Sims wrote:
> 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."

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?

>
> 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...
>

attached mail follows:


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. :)

attached mail follows:


Michael Sims wrote:
> 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

typo.

they did this people skills thing once at a company I worked for, and
one of the things they did was to get people to close the eye for
exactly 1 minute, I sat there for about 2mins - everyone thought it was
very funny. guess I've slowed down (and become more eratic) with age ;-)

> got some really slow transfer rates on your hard drives. :)

or I have a php script designed to hog exactly 99% of all resources for
no reason :-) for ten minutes, set in cron to run every hour at 49 mins
past. hihi

>

attached mail follows:


Al wrote:
> I've got a question about the following cronjob.
>
>>
>> #At 3:01 our time, run backups
>> 1 0 * * * /usr/local/bin/php
>> /www/r/rester/htdocs/auto_backup/back_em_up.php
>> >/www/r/rester/htdocs/auto_backup/cron.log 2>&1
>>
>> #At 3:02 clean up sessions folder
>> 2 0 * * * (find /www/r/rester/htdocs/sessions/ -name 'sess_*' -mtime
>> +1 -delete)
>>
>> #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 2>>&1
>>
>
> 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?
>
> And, the every minute job doesn't add anything to its log file.
>
> Apache on a virtual host. The 3:01 and 3:02 jobs have been running fine
> for months.
>
> Thanks

You guys were of immeasurable. I greatly appreciate it and hope I can help you
sometime.

attached mail follows:


Message could not be delivered

attached mail follows:


--- gustavvarupiraten.se wrote:
> I've learned to use $_REQUEST but it seems to me that it uses any
> $_GEt, or $_POST. Is it better to $_POST when I'm just using
> $_POST? It seems like that if I want "good code", but I mean is it
> faster with $_POST?

It's not faster, but it is a better practice. It is also particularly
helpful for avoiding certain types of common attacks, because it allows
(forces, actually) you to keep up with the exact origin of data.

This is also important in adhering to the HTTP specification which states
that GET requests should not perform any action other than retrieval.

Hope that helps.

Chris

=====
Chris Shiflett - http://shiflett.org/

PHP Security - O'Reilly HTTP Developer's Handbook - Sams
Coming Soon http://httphandbook.org/

attached mail follows:


I have not been successful with running PHP under DOS (no windows). Is
this possible?

TIA,
Shawn

attached mail follows:


Shawn McKenzie wrote:
> I have not been successful with running PHP under DOS (no windows). Is
> this possible?
>
> TIA,
> Shawn

For windows specific questions you are usually better off asking on the
php-windows list.

Yes this is possible. What is probably happening is your PHP script is
executing (and ending) so quickly that you don't see the output. Try this:

C:\WINNT\SYSTEM32\CMD.EXE /K "C:\PHP\php.exe -f yourfile.php"

Or if you are lazy like me, try this:
- Open Windows Explorer
- Go to Tools -> Folder Options
- Go to File Types
- Find the entry for PHP and hit "Advanced"
- Hit "New"
- For the name enter something like CLI
- For the application use C:\WINNT\SYSTEM32\CMD.EXE /K "C:\PHP\php.exe
-f %1"

At this point you can decide to make this the default action for .php
files. But at a minimum this should enable you to right-click and run a
script from the command line.

Merry Christmas (a month late even :)

--
Teach a person to fish...

Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
PHP Manual: http://www.php.net/manual/en/index.php
php-general archives: http://marc.theaimsgroup.com/?l=php-general&w=2

attached mail follows:


Thanks, but I'm not running Windows, I'm running just MS-DOS from a
bootable floppy. Hence my question :-)

PHP seems to actually be the php5ts.dll. Would there be binaries for
MS-DOS or is there a way to get this working?

Thanks!
-Shawn

Jason Barnett wrote:
> Shawn McKenzie wrote:
>
>> I have not been successful with running PHP under DOS (no windows).
>> Is this possible?
>>
>> TIA,
>> Shawn
>
>
> For windows specific questions you are usually better off asking on the
> php-windows list.
>
> Yes this is possible. What is probably happening is your PHP script is
> executing (and ending) so quickly that you don't see the output. Try this:
>
> C:\WINNT\SYSTEM32\CMD.EXE /K "C:\PHP\php.exe -f yourfile.php"
>
> Or if you are lazy like me, try this:
> - Open Windows Explorer
> - Go to Tools -> Folder Options
> - Go to File Types
> - Find the entry for PHP and hit "Advanced"
> - Hit "New"
> - For the name enter something like CLI
> - For the application use C:\WINNT\SYSTEM32\CMD.EXE /K "C:\PHP\php.exe
> -f %1"
>
> At this point you can decide to make this the default action for .php
> files. But at a minimum this should enable you to right-click and run a
> script from the command line.
>
> Merry Christmas (a month late even :)
>

attached mail follows:


DOS = 16bit
but I guess, PHP ist for 32+ bit ;)

attached mail follows:


Shawn McKenzie wrote:
> Thanks, but I'm not running Windows, I'm running just MS-DOS from a
> bootable floppy. Hence my question :-)
>
> PHP seems to actually be the php5ts.dll. Would there be binaries for
> MS-DOS or is there a way to get this working?
>
> Thanks!
> -Shawn
>

You darn trickster... don't tell me you're running DOS 3.2 even! Hehe

I don't know for certain that PHP will run on a pure DOS system. Maybe
it will, maybe it won't. In any case you can download the Windows
executable (or build it yourself from source, if you feel so brave!)
from php.net. To test if your script will work is the same as I already
stated:

cd\your\php\directory
php.exe -f yourfile.php
cross fingers and pray to whatever god(s) you might believe in. :)

--
Teach a person to fish...

Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
PHP Manual: http://www.php.net/manual/en/index.php
php-general archives: http://marc.theaimsgroup.com/?l=php-general&w=2

attached mail follows:


On Mon, 17 Jan 2005 09:23:19 -0600, Shawn McKenzie <nospammckenzies.net> wrote:
> I have not been successful with running PHP under DOS (no windows). Is
> this possible?
>
> TIA,
> Shawn

Have you downloaded the PHP zip file and added c:\php (or wherever you
 extract it) to your path?

Mike

attached mail follows:


Am 2005-01-17 16:56:12, schrieb Adrian:
> DOS = 16bit
> but I guess, PHP ist for 32+ bit ;)

Where ist the problem ?

Try to compile it with DJGPP :-)

    <http://www.delorie.com/djgpp>

I was running BOA and some other stuff for demonstration.
Maybe I put it back online.

Good Luck

Greetings
Michelle

--
Linux-User #280138 with the Linux Counter, http://counter.li.org/
Michelle Konzack Apt. 917 ICQ #328449886
                   50, rue de Soultz MSM LinuxMichi
0033/3/88452356 67100 Strasbourg/France IRC #Debian (irc.icq.com)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFB7A4hC0FPBMSS+BIRAhwsAJwI6YHdzm23sjXJl2r+HgsJcxtvLwCfSweA
02/UxmDVxeQiQijIeUclTMY=
=gpYT
-----END PGP SIGNATURE-----

attached mail follows:


On Mon, 2005-01-17 at 09:45, Shawn McKenzie wrote:
> Thanks, but I'm not running Windows, I'm running just MS-DOS from a
> bootable floppy. Hence my question :-)
>
> PHP seems to actually be the php5ts.dll. Would there be binaries for
> MS-DOS or is there a way to get this working?
>

Must be a big floppy if you are going to put it all on there :)

Bret

attached mail follows:


Hi
I have a string like this:
----
Just when you begin to think the wagon of Vietnam-grounded movies is grinding to a slow halt, you’re hit squarely in the face with another one. However, while other movies depict the gory and glory of war and its effects, this centres on the psychology of troopers before they're led to battle.
----
I need to know the index position of every occurrence of the pattern "the" in the string above, and replace it with something else. Specifically, I need the position of the last, first and third occurrences of "the".
 
I'm totally lost as to how to do this. Could someone help me out?
 
TIA,
 
Kam
 

                
---------------------------------
Do you Yahoo!?
 Yahoo! Mail - You care about security. So do we.

attached mail follows:


[snip]
I have a string like this:
----
Just when you begin to think the wagon of Vietnam-grounded movies is
grinding to a slow halt, you're hit squarely in the face with another
one. However, while other movies depict the gory and glory of war and
its effects, this centres on the psychology of troopers before they're
led to battle.
----
I need to know the index position of every occurrence of the pattern
"the" in the string above, and replace it with something else.
Specifically, I need the position of the last, first and third
occurrences of "the".
[snip]

Something like ...

$stringArray = explode(' ', $theString);
for ($i = 0; $i < count($stringArray); $i++){
        if("the" == $stringArray[$i]){
                $newStringArray[$i] = "replacing the";
        } else {
                $newStringArray[$i] = $stringArray;
        }
}
$myNewString = implode(' ', $newStringArray);

NOT tested

attached mail follows:


You need to use regular expresions, I think there is a regex_replace frunction (or something like that).

http://etext.lib.virginia.edu/helpsheets/regex.html is a fairly good introduction to regular expresions - learn to love them ;)

>>> Vikram Vaswani <mister_freehandyahoo.com> 01/17/05 03:27pm >>>
Hi
I have a string like this:
----
Just when you begin to think the wagon of Vietnam-grounded movies is grinding to a slow halt, you're hit squarely in the face with another one. However, while other movies depict the gory and glory of war and its effects, this centres on the psychology of troopers before they're led to battle.
----
I need to know the index position of every occurrence of the pattern "the" in the string above, and replace it with something else. Specifically, I need the position of the last, first and third occurrences of "the".
 
I'm totally lost as to how to do this. Could someone help me out?
 
TIA,
 
Kam
 

                
---------------------------------
Do you Yahoo!?
 Yahoo! Mail - You care about security. So do we.

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

______________________________________________________________________
This email and any files transmitted with it are confidential. It is for the intended recipient only. If you have received the email in error please notify the author by replying to this email. If you are not the intended recipient, you must not disclose, distribute, copy, print, or rely on this email. Any views expressed by an individual within this email which do not constitute or record professional advice relating to the RNLI, do not necessarily reflect the views of the organisation.

Registered Charity Number 209603

attached mail follows:


Vikram Vaswani wrote:
> Hi
> I have a string like this:
> ----
> Just when you begin to think the wagon of Vietnam-grounded movies is grinding to a slow halt, you’re hit squarely in the face with another one. However, while other movies depict the gory and glory of war and its effects, this centres on the psychology of troopers before they're led to battle.
> ----
> I need to know the index position of every occurrence of the pattern "the" in the string above, and replace it with something else. Specifically, I need the position of the last, first and third occurrences of "the".
>
> I'm totally lost as to how to do this. Could someone help me out?

take a look at the strpos() function, you'll need to use the third
(optional) argument, it should help you to determine the positions of
the occurances of the string you are looking for:

http://nl2.php.net/manual/en/function.strpos.php

>
> TIA,
>
> Kam
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Mail - You care about security. So do we.

attached mail follows:


On Mon, 2005-01-17 at 09:27, Vikram Vaswani wrote:
> Hi
> I have a string like this:
> ----
> Just when you begin to think the wagon of Vietnam-grounded movies is grinding to a slow halt, you’re hit squarely in the face with another one. However, while other movies depict the gory and glory of war and its effects, this centres on the psychology of troopers before they're led to battle.
> ----
> I need to know the index position of every occurrence of the pattern "the" in the string above, and replace it with something else. Specifically, I need the position of the last, first and third occurrences of "the".
>
> I'm totally lost as to how to do this. Could someone help me out?
>

do you want to replace them or just find the position in the string?
There are functions for both try looking at the manual for
preg_replace:

http://www.php.net/preg_replace

looks like

$replacedstr = preg_replace('/the/','whatever',$origstr,3);

would replace the first three occurances of the with whatever in the
string contained in $origstr and place it in $replacedstr.

HTH
Bret

attached mail follows:


Hi,
I am new to the PHP world so don't give me too much grief if this has a
simple solution. My problem is that the $_POST array is not being
populated. I have created a form and the method of that form is "POST". I
have started the session using session_start() but still nothing. When I
try to display what is in the array using print_r($_POST) all I get is
Array(). Did I screw up the PHP configuration?

PLEASE HELP! This is driving me mad...

Thanks
Bennie Foreman

attached mail follows:


Bennie Foreman wrote:
> Hi,
> I am new to the PHP world so don't give me too much grief if this has a
> simple solution. My problem is that the $_POST array is not being
> populated. I have created a form and the method of that form is "POST". I
> have started the session using session_start() but still nothing. When I

session_start does not matter here; it would only populate the $_SESSION
array anyways.

> try to display what is in the array using print_r($_POST) all I get is
> Array(). Did I screw up the PHP configuration?

Did you actually submit the form? I.e. did you hit the "submit" button
and print_r($_POST) on the target page?

>
> PLEASE HELP! This is driving me mad...
>
> Thanks
> Bennie Foreman

--
Teach a person to fish...

Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
PHP Manual: http://www.php.net/manual/en/index.php
php-general archives: http://marc.theaimsgroup.com/?l=php-general&w=2

attached mail follows:


[snip]
I am new to the PHP world so don't give me too much grief if this has a
simple solution. My problem is that the $_POST array is not being
populated. I have created a form and the method of that form is "POST".
I
have started the session using session_start() but still nothing. When
I
try to display what is in the array using print_r($_POST) all I get is
Array(). Did I screw up the PHP configuration?

PLEASE HELP! This is driving me mad...
[/snip]

You didn't provide much information, but try a simple script with one
item to post and then print_r($_POST)

attached mail follows:


danielelectroteque.org wrote:
> Hi list, I am needing some advise on the best way of importing classes and
> persistance, I am goingto supply some code, and would like to know if sessions or share memory is
> the best way for it.It currently serializes and unserializes the class from a session , i

speed depends partly on which mechanism you use to store serialized
data. one technique I sometimes use is to just uses files as the
serialization storage mechanism and mount the php tmp dir in RAM (which
means you need a fair ammount of RAM otherwise you'll be cutting into
your processing capabilities causes major slowdown).

> parse the directory and classusing pear naming standards, i can also send args to it. Let me know if
> there is a better way ofdoing this, as from the talk serializing is also slow. I wonder if this
> bit of code could ever becomea php extension ?? That would rock.
>

...

attached mail follows:


I am trying to get the form below to make sure the file type for the upload
is a pdf file. The code below checks, but doesn¹t allow even a pdf file to
upload. Can anybody shed some light on this for me? Is there an easier way
to do this using JS?

<?php

echo '<html>
<head>
<title>test page</title>

<script type="text/JavaScript">
<!-- Begin
function TestFileType( fileName, fileTypes ) {
if (!fileName) return;

dots = fileName.split(".")
//get the part AFTER the LAST period.
fileType = "." + dots[dots.length-1];

return (fileTypes.join(".").indexOf(fileType) != -1) ?
alert(\'That file is OK!\') :
alert("Please only upload PDF format files with the correct .pdf extension.
Please select a new file and try again.");
}
// -->
</script>

</head>

<body>
<form method="post" action="upload.php" enctype="multipart/form-data">
<input type="hidden" name="filename" value="'.$name.'">
<input type="file" name="uploadfile">
<input type="button" name="Submit" value="Upload"
onclick="TestFileType(this.form.uploadfile.value, [\'pdf\'])"><br>
</body>
</html>
';

?>

--
Gregg Healy
Service Specials Direct
800 230-8268

attached mail follows:


The code looks like this:

if(($sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) < 0){
     print("Couldn't Create Socket: " .
socket_strerror(socket_last_error()). "\n");
}
socket_set_option($sock, SOL_SOCKET,SO_RCVTIMEO, array('sec' => 1,
'usec' => 0));
$output = '';
for($i = 0; $i < count($file); $i++){
     $servernum = $file[$i];
     $i++;
     $servername = $file[$i];
     $serverport = $file2[$i];
     $serverport = preg_replace('/\s/','',$serverport);

     // Test if server online - if not, output offline. If yes, output
Online.
     if(!socket_connect($sock, $ip, $mapport)){
         print("Couldn't Create Socket: " .
socket_strerror(socket_last_error()). "\n"); // Debug
         $output .= "Server Name: " . $servername. " ~~ Offline <br />";
         continue;
     }
     else{
         $output .= "Server Name: " . $servername. " ~~ Online <br />";
     }
}

My problem now is that as it runs through the loop - it has a connection
error. Warning: socket_connect() [function.socket-connect]: unable to
connect [106]: Transport endpoint is already connected in status.php on
line 17

Even looking at examples, I cannot figure out why this error is being
produced. I cannot close the socket at the end of the loop, as it would
make any further attempts for online status impossible.

The socket_close($sock) is directly after the loop.

Thanks for any help!

attached mail follows:


* Qt <web_turyahoo.com>:
> dear Sirs,

Just a reminder... there *are* women on this group, too... ;-)

> I try to use a couple of php editor, but I am not satisfied with them.

Which editors did you try? With what were you unsatisfied?

> Any suggestion for good php editor.

One that works.

Seriously, though, this sort of question is asking for a holy war. Look
through the archives, google for it... you'll find lots of opinions.

Me, I use vim.

--
Matthew Weier O'Phinney | mailto:matthewgarden.org
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org

attached mail follows:


On 17 Jan 2005 18:55:21 -0000, Matthew Weier O'Phinney
<matthewgarden.org> wrote:
> Me, I use vim.

Amen.

--
Greg Donald
Zend Certified Engineer
http://destiney.com/

attached mail follows:


What's the purpose of your coding?
Applications? Just some sort of dynamic code here n there? or Huge OOP
application with a team of programmers?

I started with PHPEdit, Moved to Magna and then tried Dreaweaver to
communicate with designers. And then came Zend 2.5 n then Got shocked
with Zend 3.5 and now i'm on the Zend 4.0 Beta. In all the cases I'd
recommand Zend if you wish to buy rather than using a free one.

But it all depends on u & the amount of work you want to get done with
ur editor or IDE.

HTH
 
M.Saleh.E.G
97150-4779817

attached mail follows:


thanks :)
On Jan 16, 2005, at 6:05 PM, Greg Donald wrote:

> $_SERVER[ 'HTTP_USER_AGENT' ]

attached mail follows:


if u same serialized data into a file, and load it later unserialize,
it's all the same as session handler do

On Sun, 16 Jan 2005 18:59:44 +0100, Zouari Fourat <fouratgmail.com> wrote:
> but u dont need to reinitialise your variables every time the script
> loads, u need just to init them once and u get what you want wherever
> you want in your files
>
> On Sun, 16 Jan 2005 11:38:48 +0800, Xuefer Tinys <xuefergmail.com> wrote:
> > $_SESSION is same as it use serialize/unserialize, alghough there're
> > some difference
> >
> >
> > On Sat, 15 Jan 2005 10:06:58 +0100, Zouari Fourat <fouratgmail.com> wrote:
> > > what about using $_SESSION arrays ?
> > >
> > >
> > > On Fri, 14 Jan 2005 19:28:24 -0500, Al <newsridersite.org> wrote:
> > > > George Schlossnagle addresses exactly your requirement in his book "Advanced PHP
> > > > Programming".
> > > >
> > > > Josh Whiting wrote:
> > > > > Dear list,
> > > > >
> > > > > My web application (an online classifieds server) requires a set of
> > > > > fairly large global arrays which contain vital information that most all
> > > > > the page scripts rely upon for information such as the category list,
> > > > > which fields belong to each category, and so on. Additionally, there are
> > > > > a large number of function definitions (more than 13,000 lines of code
> > > > > in all just for these global definitions).
> > > > >
> > > > > These global arrays and functions never change between requests.
> > > > > However, the PHP engine destroys and recreates them every time. After
> > > > > having spent some serious time doing benchmarking (using Apache Bench),
> > > > > I have found that this code takes at least 7ms to parse per request on
> > > > > my dual Xeon 2.4ghz server (Zend Accelerator in use*). This seriously
> > > > > cuts into my server's peak capacity, reducing it by more than half.
> > > > >
> > > > > My question is: is there a way to define a global set of variables and
> > > > > functions ONCE per Apache process, allowing each incoming hit to run a
> > > > > handler function that runs within a persistent namespace? OR, is it
> > > > > possible to create some form of shared variable and function namespace
> > > > > that each script can tap?
> > > > >
> > > > > AFAIK, mod_python, mod_perl, Java, etc. all allow you to create a
> > > > > persistent, long-running application with hooks/handlers for individual
> > > > > Apache requests. I'm surprised I haven't found a similar solution for
> > > > > PHP.
> > > > >
> > > > > In fact, according to my work in the past few days, if an application
> > > > > has a large set of global functions and variable definitions, mod_python
> > > > > FAR exceeds the performance of mod_php, even though Python code runs
> > > > > significantly slower than PHP code (because in mod_python you can put
> > > > > all these definitions in a module that is loaded only once per Apache
> > > > > process).
> > > > >
> > > > > The most promising prospect I've come across is FastCGI, which for Perl
> > > > > and other languages, allows you to run a while loop that sits and
> > > > > receives incoming requests (e.g. "while(FCGI::accept() >= 0) {..}").
> > > > > However, the PHP/FastCGI modality seems to basically compare to mod_php:
> > > > > every request still creates and destroys the entire application
> > > > > (although the PHP interpreter itself does persist).
> > > > >
> > > > > Essentially I want to go beyond a persistent PHP *interpreter* (mod_php,
> > > > > PHP/FastCGI) and create a persistent PHP *application*... any
> > > > > suggestions?
> > > > >
> > > > > Thanks in advance for any help!
> > > > > Regards,
> > > > > J. Whiting
> > > > >
> > > > > * - Please note that I am using the Zend Accelerator (on Redhat
> > > > > Enterprise with Apache 1.3) to cache the intermediate compiled PHP code.
> > > > > My benchmarks (7ms+) are after the dramatic speedup provided by the
> > > > > accelerator. I wouldn't even bother benchmarking this without the
> > > > > compiler cache, but it is clear that a compiler cache does not prevent
> > > > > PHP from still having to run the (ableit precompiled) array and function
> > > > > definition code itself.
> > > >
> > > > --
> > > > PHP General Mailing List (http://www.php.net/)
> > > > To unsubscribe, visit: http://www.php.net/unsub.php
> > > >
> > > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> >
>

attached mail follows:


The answer would be Application-Scope vars.... wish we had it in PHP

M.Saleh.E.G
97150-4779817

attached mail follows:


Greetings all,

I am runnign into a strange problem.
I am working on a Linux box.
Running PHP 4.2.2
Apache 2.0
And it has MySQl installed on it (not sure of the version.

I ran a quick script to check to make sure the connection to the DB is
working fine as this is a very secure connection (have to do 2 SSH tunnesl
to get in.)

<?php
$link = mysql_connect('localhost', 'some_un', 'some_pw');
if (!$link) {
   die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

However when I ran that I got an error saying that mysql_connect is an
undefinied function??? This has got me stumped. I checked the php.ini to
make sure that mysql is turned on (which it is by default now). Nothing I
can see is telling me other wise.

 Fatal error: Call to undefined function: mysql_connect() in
/home/aiastudios/htdocs/mysql.test.php on line 13

I have noticed that on the phpinfo();
That there is no section for Mysql, which I thought was odd.

So it seems to me that mysql is disabled or something but I cannot see how
to turn it on.
Any help here would be appreciated.

--
Blessed Be

Phillip

attached mail follows:


Phillip S. Baker wrote:
> Greetings all,
>
> I am runnign into a strange problem.
> I am working on a Linux box.
> Running PHP 4.2.2
> Apache 2.0
> And it has MySQl installed on it (not sure of the version.
>
> I ran a quick script to check to make sure the connection to the DB is
> working fine as this is a very secure connection (have to do 2 SSH tunnesl
> to get in.)
>
> <?php
> $link = mysql_connect('localhost', 'some_un', 'some_pw');
> if (!$link) {
> die('Could not connect: ' . mysql_error());
> }
> echo 'Connected successfully';
> mysql_close($link);
> ?>
>
> However when I ran that I got an error saying that mysql_connect is an
> undefinied function??? This has got me stumped. I checked the php.ini to
> make sure that mysql is turned on (which it is by default now). Nothing I
> can see is telling me other wise.
>
> Fatal error: Call to undefined function: mysql_connect() in
> /home/aiastudios/htdocs/mysql.test.php on line 13
>
> I have noticed that on the phpinfo();
> That there is no section for Mysql, which I thought was odd.
>
> So it seems to me that mysql is disabled or something but I cannot see how
> to turn it on.
> Any help here would be appreciated.

mysql support is not installed. how did you install?

attached mail follows:


On Fri, 14 Jan 2005 12:34:53 -0800, Phillip S. Baker
<phillipsbakergmail.com> wrote:
> Any help here would be appreciated.

Simple.. your PHP doesn't have MySQL support. Rebuild it or install
the rpm or package or whatever. What kind of 'Linux box' is it?

--
Greg Donald
Zend Certified Engineer
http://destiney.com/

attached mail follows:


Greg Donald wrote:
> On Fri, 14 Jan 2005 12:34:53 -0800, Phillip S. Baker
> <phillipsbakergmail.com> wrote:
>
>>Any help here would be appreciated.
>
>
> Simple.. your PHP doesn't have MySQL support. Rebuild it or install
> the rpm or package or whatever. What kind of 'Linux box' is it?
>

Greg is right. Also it's important to know which version of MySQL you
want to use since it may require the mysqli library.

--
Teach a person to fish...

Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
PHP Manual: http://www.php.net/manual/en/index.php
php-general archives: http://marc.theaimsgroup.com/?l=php-general&w=2

attached mail follows:


At 08:33 PM 1/15/2005, you wrote:

>Torsten,
>Whatever the combination, it echos "February 02-2005<br>February
>02-2005<br>February 02-2005". What is wrong with it?
>
> <?php
> $week5 = "2005-02-14";
> $firstDayTs = strtotime($week5);
> $lastDayTs = $firstDayTs + (4 * 86400);
> echo date('F', $firstDayTs) . ' ' . date('m', $firstDayTs) . '-' .
> date('Y',$firstDayTs) ."<br>";
> echo date('F', $firstDayTs) . ' ' . date('m', $firstDayTs) . '-' .
> date('Y',$lastDayTs) ."<br>";
> ?>
>
>John

It is outputing what you are asking it to:
F A full textual representation of a month, such as January or March
m Numeric representation of a month, with leading zeros
Y A full numeric representation of a year, 4 digits
This is all documented at: http://us2.php.net/manual/en/function.date.php

First you are asking for the Month as a name, then the month as a number
then the year as a number. If you made $week5=2005-12-31 it would give you
the following output:
December 12-2005<br>December 12-2006<br>
If you are wanting to make it echo "February 14-18", then check out the 3rd
echo statement in the below example.

<?php
   $week5 = "2005-02-14";
   $firstDayTs = strtotime($week5);
   $lastDayTs = $firstDayTs + (4 * 86400);
   echo date('F', $firstDayTs) . ' ' . date('d', $firstDayTs) . '-' .
date('Y',$firstDayTs) ."<br>\n";
   echo date('F', $lastDayTs) . ' ' . date('d', $lastDayTs) . '-' .
date('Y',$lastDayTs) ."<br>\n";
   echo date('F', $lastDayTs) . ' ' . date('d', $firstDayTs) . '-' .
date('d',$lastDayTs) ."<br>\n";
echo "\n";
   ?>
Now, the problem with that is that if your $week5="2005-02-18" then your
results will be wrong....unless this is what you want, but the answer will
be "February 28-04". You are outputing the Month from $week5, the day from
$week5 and the day+4 of $week5 which takes it into the next month.

Steve

attached mail follows:


attached mail follows:


I looked at the 'sound like' modules in php (leveshtien, soundex) but they are
for comparing 2 strings, not creating a string based on what we already have.

I see that str_replace supports regular expessions. Without devoting hours
learning to write a regex, would it be inappropriate for me to ask how would
a regex look that basically says to str_replace "replace the n-th occurence
of $was with $willbe" and then I could just loop n==1 n==2 until
n==substr_count($data, $was);

Did I mention how much I appreciate your help in this matter? I am very
impress with the wealth of information the php community is willing to share.

Dotan

On Monday 17 January 2005 04:41 am, Richard Lynch wrote:
> Dotan Cohen wrote:
> > kayak. Focusing only on the 'k's I get this array: kayak, cayac. But I
> > need
> > kayak, kayac, cayak, cayac.
>
> You may (or may not) be able to get something going with that extra
> optional last argument to str_replace which tells how many characters to
> replace.
>
> str_replace('k', 'c', 'kayak', 1) ==> cayak
>
> You probably should step back and use soundex, or one of the other "sound
> like" modules in PHP as Greg suggested though, as a word with THREE k's in
> it will maybe be too much hassle...