php-general Digest 14 Oct 2007 10:41:03 -0000 Issue 5072

Topics (messages 263189 through 263194):

Re: Fast prefix search?
        263189 by: Nathan Nobbe
        263192 by: js

Timeout for fopen ?
        263190 by: debussy007
        263193 by: heavyccasey.gmail.com
        263194 by: Gal

Re: How to convert URL's to Links in User posted text in forms ?
        263191 by: Hemanth

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 ---
On 10/13/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
>
> On Sun, 2007-10-14 at 02:07 +0900, js wrote:
> > On 10/14/07, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
> > > can you use the php string manipulation functions ?
> >
> > I'll probably use strstr() to check whether a string starts with some
> prefix.
>
> >From the help for PHP's strstr() function:
>
>     "Note: If you only want to determine if a particular
>      needle occurs within haystack, use the faster and
>      less memory intensive function strpos() instead."
>
> So don't use strstr() use strpos(). Specifically use it like follows:
>
>     if( strpos( $haystack, $prefix ) === 0 )
>     {
>         // it's a prefix.
>     }
>

prefix, prefix... hmm.  oh, so that means the prefix string has to be at the
front of the haystack!
good catch Rob :)

-nathan

--- End Message ---
--- Begin Message ---
On 10/14/07, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
> how big is your dataset; have you tested against a potential data set and
> gotten
> long execution times?

The dataset consists of about several million lines
and I've tested script like above against the dataset.
it took almost a hour.
(perl script that uses set_range finished the job within 2 minutes)

> notice how i used strpos rather than strstr, because i got this tip from the
> docs
> Note: If you only want to determine if a particular needle occurs within
> haystack,
> use the faster and less memory intensive function strpos() instead.

On 10/14/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
> So don't use strstr() use strpos(). Specifically use it like follows:
>
>     if( strpos( $haystack, $prefix ) === 0 )
>     {
>         // it's a prefix.
>     }
>

Great tip. Thank you!

> there are some optimization points as well.  if you use a for loop, i think
> it
> will run a hair faster than the foreach, just make sure to store the length
> of the
> dictionary in an variable and use that as the sentinel control variable.
> also, if
> your search can be case insensitive you can use stripos instead of strpos,
> that will
> probly get you a little speed bump as well.

I'll try.

> if the string methods in a loop are too doggy due to the size of your
> datasets,
> you might write a program that uses berkdb and call it using the shell from
> within php.

that seems a shellscript...

Threre seems no easy solution for this job.
The best bet could be to write up do-it-your-self B-tree
implementation in PHP...

Anyway, thank you. your advice extended my knowledge a little :)

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

I want to use "fopen" to open an URL, but is it possible to add a timeout ? 
This to avoid that fopen slows down my script ?
Because if site I access takes 10 secs to respond, 
I suppose my script will just wait fopen returns something.

Thank you.
-- 
View this message in context: 
http://www.nabble.com/Timeout-for-fopen---tf4620009.html#a13194530
Sent from the PHP - General mailing list archive at Nabble.com.

--- End Message ---
--- Begin Message ---
You could use Javascript/XMLHTTP to call a PHP script that opens the file.

On 10/13/07, debussy007 <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> I want to use "fopen" to open an URL, but is it possible to add a timeout ?
> This to avoid that fopen slows down my script ?
> Because if site I access takes 10 secs to respond,
> I suppose my script will just wait fopen returns something.
>
> Thank you.
> --
> View this message in context: 
> http://www.nabble.com/Timeout-for-fopen---tf4620009.html#a13194530
> Sent from the PHP - General mailing list archive at Nabble.com.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
You can use the CURL module, which has support for timeout.
http://www.php.net/manual/en/ref.curl.php

debussy007 wrote:
> Hello,
> 
> I want to use "fopen" to open an URL, but is it possible to add a timeout ? 
> This to avoid that fopen slows down my script ?
> Because if site I access takes 10 secs to respond, 
> I suppose my script will just wait fopen returns something.
> 
> Thank you.

--- End Message ---
--- Begin Message ---
I found this on searching for "links in submitted text"
its in Ruby.... gotta convert to php and try
there are many regex samples in the php manual itself
but maybe incomplete

in = "go check out www.xyz.com or http://xyz.com";
in.gsub!(/([^/])(www.([w/_.~])*)/, '\1<a href="http://\2";
target="_blank">\2</a>')
in.gsub!(/([^"])(https?://([-w.]+)+(:d+)?(/([w/_.]*(?S+)?)?)?)/,
    '\1<a href="\2" target="_blank">\2</a>')

--- End Message ---

Reply via email to