php-general Digest 19 Aug 2005 08:03:32 -0000 Issue 3633

Topics (messages 220891 through 220925):

Apache2 x FastCGI x opcode cache
        220891 by: steve
        220892 by: steve

How to show complete exception text?
        220893 by: Christopher J. Bottaro
        220924 by: Kevin Waterson

Re: proxy security
        220894 by: Jason Barnett

Re: Be careful! Look at what this spammer did.
        220895 by: Esteamedpw.aol.com

Custom session handling - bad or good idea?
        220896 by: GamblerZG
        220897 by: Jason Barnett
        220903 by: Ben Ramsey

Re: Be careful! Look at what this spammer did. (Thank you)
        220898 by: Ryan A

preg_match
        220899 by: Jon
        220912 by: Richard Lynch

Re: run remote shell script
        220900 by: Roger Thomas

mail list test - ignore!
        220901 by: Paul Nicholson

Re: object oriented question] OO discussion newsgroups?
        220902 by: Rob Agar

previous + next buttons, no DB
        220904 by: Ashley M. Kirchner
        220906 by: Jeff Loiselle
        220908 by: Greg Donald
        220909 by: Ashley M. Kirchner
        220911 by: Philip Hallstrom

Re: PHP MySQL insert
        220905 by: Alain Reguera Delgado
        220916 by: Ben Ramsey
        220918 by: Jasper Bryant-Greene

Re: Catching all errors and redirecting
        220907 by: Jeff Loiselle

Re: previous + next buttons, no DB]
        220910 by: afan.afan.net

Re: how to clear cache content in IE using php
        220913 by: Richard Lynch
        220914 by: Stephen Johnson

Re: php cli script with if-then's very slow
        220915 by: Richard Lynch

[suspicious - maybe spam] Install PHP in Linux
        220917 by: Mario Lacunza

clearing cache contents
        220919 by: R. Ragunathan

Week Days
        220920 by: benc11.gmail.com
        220921 by: Jasper Bryant-Greene
        220922 by: Robert Cummings
        220923 by: Robert Cummings

is it worth using apache2 with php 4.3.4
        220925 by: bala chandar

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
 Hi! I have some questions about setting up Apache2/worker and using PHP via 
FastCGI and using an op-code accelerator. Namely, how do I not confuse the 
op-code accelerator into re-creating several caches in several memory 
segments.

The webserver in worker mode automatically create (for example) 5 processes 
that each run many threads. The FastCGI module runs, say 50 processes, and 
then the php default of PHP_FCGI_CHILDREN is 8. So what does this all add up 
to? And how does the accelerator group things (Zend ZPS, APC, eAccelerator)?

I am not using suexec. All for one website, not a mass-hosting situation.

Thanks!
-steve--  

--- End Message ---
--- Begin Message ---
Hi! I have some questions about setting up Apache2/worker and using PHP via
FastCGI and using an op-code accelerator. Namely, how do I not confuse the
op-code accelerator into re-creating several caches in several memory
segments.

The webserver in worker mode automatically create (for example) 5 processes
that each run many threads. The FastCGI module runs, say 50 processes, and
then the php default of PHP_FCGI_CHILDREN is 8. So what does this all add up
to? And how does the accelerator group things (Zend ZPS, APC, eAccelerator)?

I am not using suexec. All for one website, not a mass-hosting situation.

Thanks!
-steve--

--- End Message ---
--- Begin Message ---
Hi,

When an exception propagates all the way up the stack frame and splatters
itself on my webpage, most of the text is cut off!  This is completely
useless.  I can see that there is an error, but I can't read the frickin
error message.  How do I configure PHP to show the entire exception
message?

Thank you.

--- End Message ---
--- Begin Message ---
This one time, at band camp, "Christopher J. Bottaro" <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> When an exception propagates all the way up the stack frame and splatters
> itself on my webpage, most of the text is cut off!  This is completely
> useless.  I can see that there is an error, but I can't read the frickin
> error message.  How do I configure PHP to show the entire exception
> message?

not sure of your code, are you trying to do something like..
<?php

try {
   lots of good code;
}

catch(Exception $e){
  echo 'oh my, and exception has been thrown'.$e->getMessage();
}
?>

Kevin

-- 
"Democracy is two wolves and a lamb voting on what to have for lunch. 
Liberty is a well-armed lamb contesting the vote."

--- End Message ---
--- Begin Message --- The problem here is that you need an anonymous proxy server that you trust. Most of the ones you can trust aren't going to be free. However, once you've identified an anonymous proxy server which you *do* trust then you can just pipe the mails to them like any old email server would.
--- End Message ---
--- Begin Message ---
Ironically, on AOL - all of my EMAIL accounts were spammed with "test"  
(subject message) emails... approzimately 10 a day for about 5 days in a row -  
all 
which had different account names - but the same messages. So, I have a  
feeling these are all connected with the hacked forms everyone's  
experiencing...
 
- Clint

--- End Message ---
--- Begin Message --- I'm not speaking about "session_set_save_handler", I'm considering writing session handler from scratch. Is it a bad idea? If so, why?
--- End Message ---
--- Begin Message ---
This can be a fine way to go, given that you have a specific reason to
do so that is not easily handled by using session_set_save_handler. 
The most common session handler in use (besides the default handler)
is a DB session handler.  You could write this handler in C and it
would possibly be worth the effort.  Caching DB connections in a
shared module could give you a nice performance boost (although I have
no idea how stable a setup like that would be, usual caveats about
multi-threaded servers would apply).

Hope this helps.


On 8/18/05, GamblerZG <[EMAIL PROTECTED]> wrote:
> I'm not speaking about "session_set_save_handler", I'm considering
> writing session handler from scratch. Is it a bad idea? If so, why?
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

--- End Message ---
--- Begin Message ---
GamblerZG wrote:
I'm not speaking about "session_set_save_handler", I'm considering writing session handler from scratch. Is it a bad idea? If so, why?

I'm not going to say yes or no because I think it depends on your reasons, as someone else has already said, but I will point you to George Schlossnagle's _Advanced PHP Programming_ book. Take a look at pages 564 through 568. He talks about writing a custom session handler in C.

--
Ben Ramsey
http://benramsey.com/

--- End Message ---
--- Begin Message ---
Hey,
Funny, was following this thread and suddenly I got a few emails that were
almost exactly
in the same format...

Anyway, I just want to send a thank you to whoever had the bright idea of
replacing the
@ with something else its a quick and easy method and should solve that
problem (in tests
it works great...I used a str_replace as I am not too good with RegEXs)

Cheers,
Ryan

--- End Message ---
--- Begin Message ---
preg_match_all("/Charges \s\s+ $total x (.+) /siU", $single, $from_invoice);

The text has "Charges" then a variable amount of spaces a previously picked
decimal number" x " (and the data I want)" "

is this correct or am I missing something?  It seems to work sometimes and
not others and I have not quite figured out what makes it fail.

The error I get is
Warning: preg_match_all(): unknown modifier '#' in "file"

--- End Message ---
--- Begin Message ---
On Thu, August 18, 2005 2:50 pm, Jon wrote:
> preg_match_all("/Charges \s\s+ $total x (.+) /siU", $single,
> $from_invoice);

I would recommend using \\s instead of \s -- While \s doesn't have any
meaning in PHP strings, so PHP just figures you must have meant \\s

> The text has "Charges" then a variable amount of spaces a previously
> picked
> decimal number" x " (and the data I want)" "
>
> is this correct or am I missing something?  It seems to work sometimes
> and
> not others and I have not quite figured out what makes it fail.
>
> The error I get is
> Warning: preg_match_all(): unknown modifier '#' in "file"

Does $single have a "#" character in it by any chance???

Ooooh.  Or does $total sometimes have "/#" in it?

Imagine that $total has "#/#" in it.

Then your PRCE string turns into:
"/Charges \s\s+ #/# x (.+) /siU"
        v--------^
Preg "sees" this / to end the search string, and then it sees a #
after that, and thinks you are trying to use # the way you are using
"siU" at the end.

Only # ain't a valid character in that location.

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

--- End Message ---
--- Begin Message ---
Thanks Matthew. You and Richard have been very helpful. I should be able to 
carry on. Thank you again.

--
Roger

Quoting Matthew Weier O'Phinney <[EMAIL PROTECTED]>:

> First off, Roger, Thomas, not sure which is your given name --
> please
> use a mail or news agent that will wrap your lines with linebreaks at
> 72
> characters. Some of us are on text-based clients, and it's difficult
> to
> read your posts when they extend beyond the screen boundaries... ;-)
> 
> * Roger Thomas <[EMAIL PROTECTED]> :
> > OK. I am able to setup remote key authentication between svrA and
> > svrB. From svrA I can login to svrB with something like
> > [EMAIL PROTECTED] www]$ ssh [EMAIL PROTECTED]
> >
> > and I can also execute a shell script like
> > [EMAIL PROTECTED] www]$ ssh [EMAIL PROTECTED] /tmp/test.sh
> >
> > On svrA I have a PHP script like so:
> > <?
> > system('ssh [EMAIL PROTECTED] /tmp/test.sh someDIR');
> > ?>
> >
> > /tmp/test.sh on svrB is only a one liner like so:
> > mkdir /tmp/$1
> >
> > I ran the script from the browser but the /tmp/someDIR is not
> created :(
> > Could it be that user nobody on svrA is *not* allowed to connect
> to
> > svrB because the public key belongs to user www ? How do I rectify
> > this ?
> >
> > In the actual situation, I need to execute a shell script in svrB
> > (from browser served by Apache on svrA) that only root can run.
> Please
> > advise. I am getting very worried.
> 
> Okay, I should have been a little more explicit. 
> 
> There are two ways I've done this. The initial details are
> different,
> but the final call is pretty much the same. 
> 
> 1. Using sudo
>    'sudo' allows users to run commands as different users. In this
> case,
>    we want the user running the web server (usually www, apache, or
>    nobody) to run ssh, or a script that executes the ssh command, as
> a
>    normal user. I usually opt for the latter, and create a script
> such
>    as:
> 
>        #!/bin/bash
>        exec ssh [EMAIL PROTECTED] /path/to/remote/script
> 
>    and save it in /usr/local/bin. Then, edit sudoers (usually
> executing
>    'visudo' as root), and add a line like
> 
>        nobody ALL = (username) NOPASSWD: /usr/local/bin/SCRIPTNAME
> 
>    What this does is to allow the user 'nobody' (or whomever runs
> the
>    web server process) to execute /usr/local/bin/SCRIPTNAME as
>    'username', and they do not need to enter a password to do so
>    (normally with sudo you do).
> 
>    You'll need to restart the webserver after granting the sudo
>    privileges.
> 
>    In this scenario, the normal user, specified by 'username' above,
>    needs to have the the SSH keys setup between the servers.
> 
> 2. Give the web user a home directory
>    The other option is to setup a home directory for the web user.
> This
>    will mean editing the /etc/passwd file to give the web user both
> a
>    home directory and a shell; these are teh last two items in the
> colon
>    delimited list. A sample entry might look like:
> 
>        nobody:x:65534:65534:nobody:/var/www:/bin/bash
>    
>    Once you've done this, restart the web server. At this point,
> you'll
>    then need to become the web user briefly in order to:
> 
>       * generate an SSH key
>       * send the key to the remote server
> 
>    Then, on the remote server, add the SSH key to the appropriate
> user
>    on that system.
> 
> Good luck!
> 
> > Quoting Matthew Weier O'Phinney <[EMAIL PROTECTED]> :
> >
> > > * Roger Thomas <[EMAIL PROTECTED]> :
> > > > My PHP script is in svrA. How do I run a shell script in svrB?
> > > > svrB does not have PHP and Apache :(
> > > > Is this at all possible? Please advise.
> > > 
> > > Use ssh. You will have to setup remote key authentication from
> svrA to
> > > svrB (so that a password will not be needed), and then in your
> script
> > > you would call:
> > > 
> > >     system('ssh svrB /path/to/scriptToRun');
> 
> -- 
> Matthew Weier O'Phinney
> Zend Certified Engineer
> http://weierophinney.net/matthew/
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 





---------------------------------------------------
Sign Up for free Email at http://ureg.home.net.my/
---------------------------------------------------

--- End Message ---
--- Begin Message ---
Hey guys!
Just testing...

Paul

--- End Message ---
--- Begin Message ---
hi Alex,

I don't know of any discussion group, but you may want to check out a
book that's just got a very good review on slashdot...

http://books.slashdot.org/article.pl?sid=05/08/16/0434205&from=rss

Rob

> -----Original Message-----
> From: Alex Gemmell [mailto:[EMAIL PROTECTED] 
> Sent: Friday, 19 August 2005 12:42 AM
> To: [email protected]
> Subject: [PHP] [OFF: object oriented question] OO discussion 
> newsgroups?
> 
> 
> Hello,
> 
> I'd like to join a newsgroup that discusses object oriented design 
> techniques.  I'm getting to grips with OO stuff but could do 
> with some 
> specific guidance at times, especially while I'm a novice at it.
> 
> I can't see an OO newsgroup here in news.php.net.
> 
> Thanks for any suggestions.
> 
> Alex
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--- End Message ---
--- Begin Message ---

I have a client that maintains picture galleries by simply dropping images into a directory. I have a template created that when loaded, with a specific $ID, will load the image that corresponds to that $ID. The request now is to have previous and next buttons that web surfers can click on to cycle through the rest of the images in the directory (instead of having to close that pop-up and click on another image to look at.)

What's the best way to go about this? Since I don't have a list of images in any kind of array (such as a result from DB query), I'm a bit at a loss here. Obviously if someone clicks on the first image on the gallery page, it should only have a 'next' button, and if they click the last image, it should only have a 'previous' button, but anything else on the page should have a 'previous' and 'next' button. I just don't know how to keep that relationship or how to start coding that.

   Ideas/suggestions/pointers are much appreciated here.

--
R | I haven't lost my mind; it's backed up on tape somewhere.
 +--------------------------------------------------------------------
 Ashley M. Kirchner <mailto:[EMAIL PROTECTED]>   .   303.442.6410 x130
 IT Director / SysAdmin / WebSmith             .     800.441.3873 x130
 Photo Craft Laboratories, Inc.            .     3550 Arapahoe Ave. #6
 http://www.pcraft.com ..... .  .    .       Boulder, CO 80303, U.S.A.

--- End Message ---
--- Begin Message ---
Ashley,

How are you creating the gallery page? You must be reading the filenames in the directory and producing an <img> for each one. Can you create an array of those filenames, save it to session (or generate it each time), and iterate through them?
--- End Message ---
--- Begin Message ---
On 8/18/05, Ashley M. Kirchner <[EMAIL PROTECTED]> wrote:
> Since I don't have a list of
> images in any kind of array (such as a result from  DB query)

Sure you do.

#!/usr/bin/php
<?php

$a = array();
$d = dir( '.' );
while( false !== ( $e = $d->read() ) )
{
  $a[] = $e;
}
$d->close();
print_r( $a );

?>


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

--- End Message ---
--- Begin Message ---
Jeff Loiselle wrote:

Ashley,

How are you creating the gallery page? You must be reading the filenames in the directory and producing an <img> for each one. Can you create an array of those filenames, save it to session (or generate it each time), and iterate through them?

   Say the images are in a folder called /gallery/

Within that, I have an index.php that is manually coded to have thumbnails of the images displayed in a grid. Important to note: they're in a very specific (artistic) order. Each one of those thumbnails is linked to one and the same popup.php file that is simply another php file that expects an $ID passed to it. That $ID, which again is hard coded in index.html, tells popup.php which file to display. (that $ID is basically the file name of the image, so I can append it to the <img /> tag as the page loads.

So you see, I have no array of anything. The index.html file gets manually edited every time something is added or removed. This is why I'd like a programmatic way of a) generating that file, so that the client can add/remove images as they see fit, and b) be able to have prev/next buttons on the popup window.

   Does that make sense?

--
R | I haven't lost my mind; it's backed up on tape somewhere.
 +--------------------------------------------------------------------
 Ashley M. Kirchner <mailto:[EMAIL PROTECTED]>   .   303.442.6410 x130
 IT Director / SysAdmin / WebSmith             .     800.441.3873 x130
 Photo Craft Laboratories, Inc.            .     3550 Arapahoe Ave. #6
 http://www.pcraft.com ..... .  .    .       Boulder, CO 80303, U.S.A.

--- End Message ---
--- Begin Message ---
Ashley,

How are you creating the gallery page? You must be reading the filenames in the directory and producing an <img> for each one. Can you create an array of those filenames, save it to session (or generate it each time), and iterate through them?

  Say the images are in a folder called /gallery/

Within that, I have an index.php that is manually coded to have thumbnails of the images displayed in a grid. Important to note: they're in a very specific (artistic) order. Each one of those thumbnails is linked to one and the same popup.php file that is simply another php file that expects an $ID passed to it. That $ID, which again is hard coded in index.html, tells popup.php which file to display. (that $ID is basically the file name of the image, so I can append it to the <img /> tag as the page loads.

So you see, I have no array of anything. The index.html file gets manually edited every time something is added or removed. This is why I'd like a programmatic way of a) generating that file, so that the client can add/remove images as they see fit, and b) be able to have prev/next buttons on the popup window.

Change it. Remove all the hardcodings from index.html. Instead create another data file that contains the list of images (and the order) you want them displayed. Easier for you if that file is a PHP file that looks something like:

$img_array = array(
        "img1",
        "img3",
        "img2",
);

But it could just as easily look like this:

img1
img3
img2

Note that I'm only putting in the "basename" of the image, not the full name. Hopefully you can determine the path to the thumbnail and full image from this basename.

If you can't make it look like this:

img1thumb.jpg img1.jpg
...

Then turn your index.html into a index.php file that includes (or processes) this data file. Now you've got an array you can loop through to display the thumbnails.

Change your popup.php page to read that data file in as well. And now you can loop through it to find the image you're viewing. Keep track of a counter and if that counter is greater than zero, display a previous link. If it's less then the total count of the array minus one, display a next link.

I'd take it a step further still and have each separate index.php include a master index.php (same for popup.php) so that the only thing a specific directories index.php contains is:

include_once("/path/to/master/index.php");

That way you can make global code changes without touching all the files.

Good luck!

-philip

--- End Message ---
--- Begin Message ---
you could try:

1. get all form variables into an array
2. validate values
3. convert all values into entities using htmlentities()
4. build sql query (do some tests 'til get it right)
5. execute the built query (with proper db function)

by now, commas aren't a problem, they are limited between sql query's
quotes. If some quotes are inserted as value they are previously 
converted to its entities and do not break the sql query.

as previously said in this thread, the problem is on quoting and maybe
on converting the values to entities, to prevent some quote break the
sql structure.

--- End Message ---
--- Begin Message ---
Alain Reguera Delgado wrote:
you could try:

1. get all form variables into an array

fine

2. validate values

Good, but do this step as you put the values into a separate array, don't put all the values into the array first and then validate them later... make sure the input received is input expected and then save only the input to the array that passes the validation/filtering tests

3. convert all values into entities using htmlentities()

Why do you want to do this before saving to the database? This step has absolutely no bearing on preparing the statement for insertion into a database. It won't protect against SQL injection. Also, you will never be able to do anything with this data other than use it for HTML output (unless you try to reverse the entities, which seems like an awful lot of work to me). It's best to save the raw data as entered and escape it (with htmlentities() or something else) ONLY on output.

As I mentioned in my last post to this thread, the best way to escape a string for insertion into a database (and protect against SQL injection) is to use the escape function for the particular database -- mysql_real_escape_string() in this case. You should never use htmlentities() to escape data before saving it to a database. Do that only after you've pulled data from the database and are outputting it somewhere (like on a Web page).

4. build sql query (do some tests 'til get it right)
5. execute the built query (with proper db function)

by now, commas aren't a problem, they are limited between sql query's
quotes. If some quotes are inserted as value they are previously converted to its entities and do not break the sql query.

This is why you use mysql_real_escape_string(), etc. -- not htmlentities().

as previously said in this thread, the problem is on quoting and maybe
on converting the values to entities, to prevent some quote break the
sql structure.

You don't need to convert the values to HTML entities when saving to a database. That's not going to prevent this problem.

--
Ben Ramsey
http://benramsey.com/

--- End Message ---
--- Begin Message ---
Ben Ramsey wrote:
You don't need to convert the values to HTML entities when saving to a database. That's not going to prevent this problem.

Furthermore, you don't need to use htmlentities() if you specify your character set properly and all the characters you are outputting are in your character set.

For example, I use UTF-8 for all output, and all the characters I ever use are (of course) in the UTF-8 character set. Therefore I only need to use htmlspecialchars() to turn characters that have special meaning in HTML (&, ', ", <, >, etc.) into entities.

Jasper

--- End Message ---
--- Begin Message --- You can also try output buffering the whole page, checking for an error with string functions, and email yourself if there is an error. ;-)
--- End Message ---
--- Begin Message ---
if you have all images in one directory and ONLY images in that folder

you can try something like this:

  $path = '/path/to/directory/with/images';
  $handle = opendir($path);
  while (false != ($file = readdir($handle)))
  {
if ($file != "." && $file != ".." && !ereg('.php', $file)) #excluding . and .. files and php file with this code
      {
          $images[] = $file;
      }
  }
  closedir($handle);

  $last = count($images);
  foreach($images as $key => $value)
  {
     swtich($key)
     {
         case (0):
           echo '[ next ]';
           break;
         case ($last):
           echo '[ prevous ]';
           break;
         default:
           echo '[ previous ] [ next ]';
           break;
      }
  }


I hope this will help
;)

-afan

Ashley M. Kirchner wrote:


I have a client that maintains picture galleries by simply dropping images into a directory. I have a template created that when loaded, with a specific $ID, will load the image that corresponds to that $ID. The request now is to have previous and next buttons that web surfers can click on to cycle through the rest of the images in the directory (instead of having to close that pop-up and click on another image to look at.)

What's the best way to go about this? Since I don't have a list of images in any kind of array (such as a result from DB query), I'm a bit at a loss here. Obviously if someone clicks on the first image on the gallery page, it should only have a 'next' button, and if they click the last image, it should only have a 'previous' button, but anything else on the page should have a 'previous' and 'next' button. I just don't know how to keep that relationship or how to start coding that.

   Ideas/suggestions/pointers are much appreciated here.


--- End Message ---
--- Begin Message ---
On Thu, August 18, 2005 2:38 am, R. Ragunathan wrote:
>  how to clear the contents of cache in Internet explorer
> using php.If any one finds the solution do reply.

The people saying "you can't" are technically correct, of course.

You can't clear out the cache on a user's hard drive, because that
would give you FAR too much power over their computer.

Though I'm not sure how different that is from them running Windows in
the first place. :-)

The answer that you can send headers to avoid caching of content are
kind of sort of correct, except that various browsers, servers, AOL
Servers (enough unlike other servers to be their own category), and
various other caching systems *WILL* cache your stuff, no matter what
combination of standard, non-standard, and outright stupid headers you
send out.

There is ALWAYS somebody who thinks they have a right to cache your
content, no matter how WRONG they are.

One trick I frequently use is to simply embed a RANDOM element in a URL.

For example:
http://example.com/dynamic_image.php
will get turned into:

http://example.com/dynamic_image/847347372634581/dynamic_image.jpg

EG:
http://example.com/dynamic_image/<?php echo mt_rand()?>/dynamic_image.jpg
[that was supposed to be all one line]

The image will still get cached, but since you never use that URL
again, you don't really need to worry about it.

This makes IE's cache completely useless.

Well, okay, it was already completely useless, but it's a different
KIND of uselessness.

Note that in the above URL, "dynamic_image" is the actual PHP script,
the random number is ignored by the script, and the dynamic_image.jpg
is there simply to "fool" the browser.

Maybe if everybody did this, MS would realize how broken their
cache-handling is and fix it... Nah.  They'd just break it even worse.

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

--- End Message ---
--- Begin Message ---


On 8/18/05 9:06 PM, "Richard Lynch" <[EMAIL PROTECTED]> wrote:

> 
> Maybe if everybody did this, MS would realize how broken their
> cache-handling is and fix it... Nah.  They'd just break it even worse.


Is someone feeling a bit cynical tonight? Nah.  Not just tonight ;)


-- 
Stephen Johnson
The Lone Coder

http://www.ouradoptionblog.com
*Join us on our adoption journey*

[EMAIL PROTECTED]
http://www.thelonecoder.com

*Continuing the struggle against bad code*
--

--- End Message ---
--- Begin Message ---
On Thu, August 18, 2005 2:14 am, Frans Fierens wrote:
> I've noticed that php cli scripts using for-loops with some
> if...then's
> are very slow using the php cli (command line interface). The
> following
> php script takes somewhat 100 seconds (php v5.0.3 on a redhat linux, 3
> Ghz PC). The same program in c (see below) less than 1 second ... I
> know
> that php is a scripting language, but isn't the difference between de
> c
> compiled prog and de php script not very extreme ?

In the unlikely event that you ever need code like that in a real-life
application, write that part of your code in C as a Module for
Apache/PHP.

A cache like the Zend cache would maybe help a LITTLE as it will parse
it all to byte-code only once.  Though I suspect it won't help that
much, as it will still have run through that byte-code over and over.

Do feel free to write all your web server application in C if
performance is your primary consideration. :-)

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

--- End Message ---
--- Begin Message ---
Hello,

Im newbie in Linux and I need your help for install PHP5 in my Ubuntu
5.04 Linux distro, any links, manuals, etc

Thansk in advance!!

-- 
Saludos / Best regards

Mario Lacunza
Desarrollador de Sistemas - Webmaster
Email: [EMAIL PROTECTED]
Email: [EMAIL PROTECTED]
Messenger MSN: [EMAIL PROTECTED]
Website: http://www.lacunza.tk
Lima - Peru

--- End Message ---
--- Begin Message ---

hi,

 can anyone provide me a solution for clearing the 
cache contents on the clientside using javascript.

--- End Message ---
--- Begin Message ---
I am trying to add 3 (or a user-defined amount) week days to a certain date.. 
An example is today 2005-08-18 then adding 3 week days to give me a date of 
2005-08-23. I have tried searching online but cannot find an easy way of 
doing so.

--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
I am trying to add 3 (or a user-defined amount) week days to a certain date.. An example is today 2005-08-18 then adding 3 week days to give me a date of 2005-08-23. I have tried searching online but cannot find an easy way of doing so.

$numDaysToAdd = 3;
$s = ($numDaysToAdd == 1) ? '' : 's';

$dayInFuture = strtotime("+$numDaysToAdd day$s");
$dayName = date('l', $dayInFuture);
if($dayName == 'Saturday') {
        $dayInFuture = strtotime("+2 days", $dayInFuture);
} else if($dayName == 'Sunday') {
        $dayInFuture = strtotime("+1 day", $dayInFuture);
}

Disclaimer: untested code.

Jasper

--- End Message ---
--- Begin Message ---
On Fri, 2005-08-19 at 02:10, Jasper Bryant-Greene wrote:
> [EMAIL PROTECTED] wrote:
> > I am trying to add 3 (or a user-defined amount) week days to a certain 
> > date.. 
> > An example is today 2005-08-18 then adding 3 week days to give me a date of 
> > 2005-08-23. I have tried searching online but cannot find an easy way of 
> > doing so.
> 
> $numDaysToAdd = 3;
> $s = ($numDaysToAdd == 1) ? '' : 's';
> 
> $dayInFuture = strtotime("+$numDaysToAdd day$s");
> $dayName = date('l', $dayInFuture);
> if($dayName == 'Saturday') {
>       $dayInFuture = strtotime("+2 days", $dayInFuture);
> } else if($dayName == 'Sunday') {
>       $dayInFuture = strtotime("+1 day", $dayInFuture);
> }
> 
> Disclaimer: untested code.

This doesn't work since the value can be user defined and thus may span
multiple weeks :) The following works but is dirty, I'm sure there's a
better solution using modulus operator and adding and subtracting and a
little voodoo... I'm just too lazy atm to think it up ;)

<?php

$weekdays = array
(
    'Mon' => true,
    'Tue' => true,
    'Wed' => true,
    'Thu' => true,
    'Fri' => true,
);

$daySeconds = (60 * 60 * 24);

$start = time();
$addWeekdays = 3;

$final = $start;
while( $i < $addWeekdays )
{
    $final += $daySeconds;
echo date( 'D', $final )."\n";
    if( isset( $weekdays[date( 'D', $final )] ) )
    {
        $i++;
    }
}

echo 'Start: '.date( 'Y-m-d (D)', $start )."\n";
echo 'Final: '.date( 'Y-m-d (D)', $final )."\n";

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
On Fri, 2005-08-19 at 02:17, Robert Cummings wrote:
> This doesn't work since the value can be user defined and thus may span
> multiple weeks :) The following works but is dirty, I'm sure there's a
> better solution using modulus operator and adding and subtracting and a
> little voodoo... I'm just too lazy atm to think it up ;)

Ok so I felt like doing it :)

<?php

//
// For every 5 days to add we wrap a week and are right back where we
// started so... 
//

$addWeekdays = isset( $argv[1] ) ? $argv[1] : 0; // command line for fun
$start = time();

$addWeeks = (int)($addWeekdays / 5);
$addWeekDays = ($addWeekdays % 5);

$daySeconds = (24 * 60 * 60);

$final = $start + ($addWeeks * 7 * $daySeconds);
while( $addWeekDays > 0 )
{
    $final += $daySeconds;

    $day = date( 'D', $final );
    if( $day != 'Sat' && $day != 'Sun' )
    {
        $addWeekDays--;
    }
}

echo 'Start: '.date( 'Y-m-d (D)', $start )."\n";
echo 'Final: '.date( 'Y-m-d (D)', $final )."\n";


-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
Hi,

i am now using apache 1.3.x with php 4.3.4

is it worth upgrading to apache 2.x
-- 
bala> balachandar muruganantham
Y!   > mbchandar
Hotmail >  mbchandar
blog> lynx http://chandar.blogspot.com
web> http://www.chennaishopping.com

--- End Message ---

Reply via email to