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 11 Apr 2006 04:46:42 -0000 Issue 4065

php-general-digest-helplists.php.net
Date: Mon Apr 10 2006 - 23:46:42 CDT


php-general Digest 11 Apr 2006 04:46:42 -0000 Issue 4065

Topics (messages 233674 through 233738):

Re: mod_rewrite q's: syntax?
        233674 by: Joe Wollard
        233695 by: Richard Lynch
        233709 by: Micky Hulse
        233711 by: Micky Hulse
        233716 by: Richard Lynch
        233729 by: Micky Hulse

how to assign a value to a variable inside a class
        233675 by: Merlin
        233676 by: Brad Bonkoski
        233678 by: Dave Goodchild

Re: function by reference
        233677 by: tedd
        233722 by: Richard Lynch
        233723 by: Ray Hauge
        233724 by: Ray Hauge

Re: RSS Generation
        233679 by: Dave Goodchild
        233680 by: Frank Arensmeier
        233682 by: php.swimwebs.com
        233684 by: php.swimwebs.com
        233690 by: Richard Lynch
        233691 by: Richard Lynch

A question about max_execution_time
        233681 by: Eric Butera
        233683 by: Ray Hauge
        233685 by: Eric Butera
        233686 by: Ray Hauge
        233688 by: Richard Lynch

simpleXML - simplexml_load_file() timeout?
        233687 by: darren kirby
        233696 by: Robert Cummings
        233699 by: darren kirby
        233700 by: Robert Cummings
        233701 by: darren kirby
        233702 by: Martin Alterisio
        233703 by: darren kirby
        233707 by: Rasmus Lerdorf
        233708 by: Richard Lynch
        233710 by: Richard Lynch
        233713 by: darren kirby
        233715 by: Robert Cummings
        233718 by: Richard Lynch
        233725 by: Martin Alterisio
        233726 by: Rasmus Lerdorf
        233728 by: Rasmus Lerdorf
        233731 by: Richard Lynch
        233732 by: Rasmus Lerdorf
        233733 by: Robert Cummings
        233734 by: Rasmus Lerdorf
        233735 by: Robert Cummings
        233736 by: Robert Cummings
        233737 by: Rasmus Lerdorf

Browser-based scanning
        233689 by: Dan Harrington
        233692 by: John Nichel
        233705 by: Richard Lynch

Re: Implied permissions
        233693 by: Michael Felt

Re: String /pattern formatting extraction question
        233694 by: Richard Lynch

String is not zero-terminated
        233697 by: Richard Lynch
        233698 by: Kristen G. Thorson
        233704 by: Richard Lynch
        233706 by: Curt Zirzow
        233712 by: Richard Lynch

Re: Argument passed by reference?
        233714 by: Chris
        233717 by: tedd
        233719 by: Chris

Re: php with ajax - uploading pictures
        233720 by: Richard Lynch
        233730 by: Manuel Lemos

Re: stripping enclosed text from PHP code
        233721 by: Richard Lynch

PHP and CakePHP: How to use the $html->selectTag()
        233727 by: Pham Huu Le Quoc Phuc

flash file to recognize SESSION or REQUEST variables?
        233738 by: Sunnrunner

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:


Mickey,

I'm not an expert on the topic by any stretch of the imagination, but I seem
to recall reading that it's best to move everything into httpd.conf for
performance reasons. You may want to investigate that, but otherwise I don't
see anything wrong with what you're doing.

On 4/10/06, Micky Hulse <mickyambiguism.com> wrote:
>
> Well, I added this to the end of my .htaccess:
>
> # Set the index page:
> RedirectMatch ^/$ http://mydomain.com/folder/folder/index.php
>
> Seems to work well, but I am still concerned about
> pitfalls/optimization/consolidation... er, perfection? ;)
>
> TIA, Cheers,
> Micky
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

attached mail follows:


On Mon, April 10, 2006 12:50 am, Micky Hulse wrote:
>> -----Original Message-----
>> From: Chris [mailto:dmagickgmail.com]
>> Do you need to do it with a mod_rewrite?
>>
>> if not, you can do it easily in php:
>>
>> header('location: folder/file.php');
>> exit();
>>
>> in index.php.
>
>
> Unfortunately, yes... I am using a CMS, and my current setup is
> forcing me
> into using the more complicated mod_rewrite.
>
> Well, not that it is a bad thing... seems like mod_rewrite is more
> search-engine/bot friendly.
>
> Thanks for the tip though, I really appreciate your time.

Another alternative, if mod_rewrite confuses you as much as it does me...

.htaccess
<Files folder>
  ForceType application/x-httpd-php
</Files>
DocumentIndex folder

folder
<?php
  $pathinfo = $_SERVER['PATH_INFO']; //I always forget if it's
PATHINFO or...
  //do whatever you want with the $pathinfo to include the right code
or return the right content or...
?>

On the plus side, this doesn't force people into example.com when they
went to www.example.com -- It just works. :-)

PS

I you do stick with mod_rewrite, turn mod_rewrite_debug *ON* and tail
-f your http error_log for awhile.

You'll learn a lot about what will/won't work for mod_rewrite in your
rules...

The warnings about mod_rewrite debugging/logging performance issues
are a bit over-stated, I think...

Or, at least, you need to do this on a development server with "real"
traffic patterns for your testing, if doing it live is a non-option.

Doing it on only the URLs *you* think of typing doesn't count. Those
pesky real users can come up with some really interesting URLs to
type... :-)

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

attached mail follows:


> -----Original Message-----
> From: Joe Wollard [mailto:joe.wollardgmail.com]
> I'm not an expert on the topic by any stretch of the
> imagination, but I seem to recall reading that it's best to
> move everything into httpd.conf for performance reasons. You
> may want to investigate that, but otherwise I don't see
> anything wrong with what you're doing.

Sounds good to me, thanks so much for you help. Reading about httpd.conf
now.

Have a great day/week/month/year/...
Cheers,
Micky

attached mail follows:


Hi Richard,

> Doing it on only the URLs *you* think of typing doesn't count. Those
> pesky real users can come up with some really interesting URLs to
> type... :-)

Lol, I was thinking that might be a problem.

Thanks for all the great tips, I really appreicate your help.

Great info... I am looking forward to learning more about the information
you presented.

Btw, anyone have any good tips for setting-up outlook to format list emails
better? I just got a PC and am coming from the Mac world (Mail app was
pretty simple compared to all the Microsoft bells and whistles)...

Have a good one,
Cheers,
Micky

attached mail follows:


On Mon, April 10, 2006 7:08 pm, Micky Hulse wrote:
>> Doing it on only the URLs *you* think of typing doesn't count.
>> Those
>> pesky real users can come up with some really interesting URLs to
>> type... :-)
>
> Lol, I was thinking that might be a problem.
>
> Thanks for all the great tips, I really appreicate your help.
>
> Great info... I am looking forward to learning more about the
> information
> you presented.
>
> Btw, anyone have any good tips for setting-up outlook to format list
> emails
> better? I just got a PC and am coming from the Mac world (Mail app was
> pretty simple compared to all the Microsoft bells and whistles)...

Abandon Outlook and use Eudora, or Pegasus, or webmail, or ANYTHING
other than Outlook? :-)

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

attached mail follows:


> -----Original Message-----
> From: Richard Lynch [mailto:ceol-i-e.com]
> Abandon Outlook and use Eudora, or Pegasus, or webmail, or ANYTHING
> other than Outlook? :-)

LOL! Yeah, I do not know what I was thinking in the first place... Eudora
sounds good to me. :D

Cheers,
Micky

attached mail follows:


Hi there,

I would like to assign a value inside a class like this:

var $db_username = $old_name;

Unfortunatelly this does not work and I do get following error:
Parse error: syntax error, unexpected T_VARIABLE, expecting T_OLD_FUNCTION or
T_FUNCTION or T_VAR or '}'

Thank you for any hint on how to place a correct syntax on this.

Merlin

attached mail follows:


How about this:

class foo {
    var $name;

    function setName($value) {
       $this->name = $value;
    }
}

-B

Merlin wrote:

>
> Hi there,
>
> I would like to assign a value inside a class like this:
>
> var $db_username = $old_name;
>
> Unfortunatelly this does not work and I do get following error:
> Parse error: syntax error, unexpected T_VARIABLE, expecting
> T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}'
>
> Thank you for any hint on how to place a correct syntax on this.
>
> Merlin
>

attached mail follows:


use a setter function. Direct var assignments must be simple constants. A
setter function enforces encapsulation.

On 10/04/06, Merlin <news.groupsweb.de> wrote:
>
>
> Hi there,
>
> I would like to assign a value inside a class like this:
>
> var $db_username = $old_name;
>
> Unfortunatelly this does not work and I do get following error:
> Parse error: syntax error, unexpected T_VARIABLE, expecting T_OLD_FUNCTION
> or
> T_FUNCTION or T_VAR or '}'
>
> Thank you for any hint on how to place a correct syntax on this.
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
http://www.web-buddha.co.uk
dynamic web programming from Reigate, Surrey UK

look out for e-karma, our new venture, coming soon!

attached mail follows:


> > Boy, am I in love with this language -- it gives you plenty of
>> shovels to dig yourself in as deep as you want.
>
>*lol*. personally I prefer the other format which was what I tried to
>illustrate with my original example:

Oh, you illustrated it very well. I looked intently at it and learned
from it. I'm just into "one focus" when I ask those type of
questions. I had something very specific in mind and that last post
you may hit the mark!

Thanks again.

tedd

--
--------------------------------------------------------------------------------
http://sperling.com

attached mail follows:


<?php
function foo { echo "Hi";}
$bar = 'foo';
$bar();
?>

On Sun, April 9, 2006 1:17 pm, tedd wrote:
> Hi gang:
>
> Not that I have an immediate need for this, but in other languages
> one can access a function by reference (in other words, it's address
> -- such as call(function address) ).
>
> In php, one can pass a variable by reference by simply using the
> ampersand, such a &$a.
>
> Is there a similar way to reference a function?
>
> Rob, was kind enough to post the following code, but I was looking
> for something where I could store the function's address in a
> variable. Something like:
>
> $a = &f_a();
>
> And then, where I could use call_user_func($a); (or something
> similar) and the function would do it's thing -- anything like that?
>
> Thanks
>
> tedd
>
> --- Rob's suggestion follows.
>
> Like the following?
>
> <?php
>
> function f_a()
> {
> echo 'a';
> }
>
> function f_b()
> {
> echo 'b';
> }
>
> function f_c()
> {
> echo 'c';
> }
>
> $map = array
> (
> 'a' => 'f_a',
> 'b' => 'f_b',
> 'c' => 'f_c',
> );
>
> $map['a']();
> $map['b']();
> $map['c']();
>
> ?>
>
>
> --
> --------------------------------------------------------------------------------
> http://sperling.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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

attached mail follows:


On Monday 10 April 2006 19:19, Richard Lynch wrote:
> On Sun, April 9, 2006 1:17 pm, tedd wrote:
> > Hi gang:
> >
> > Not that I have an immediate need for this, but in other languages
> > one can access a function by reference (in other words, it's address
> > -- such as call(function address) ).
> >
> > In php, one can pass a variable by reference by simply using the
> > ampersand, such a &$a.
> >
> > Is there a similar way to reference a function?
> >
> > Rob, was kind enough to post the following code, but I was looking
> > for something where I could store the function's address in a
> > variable. Something like:
> >
> > $a = &f_a();
> >
> > And then, where I could use call_user_func($a); (or something
> > similar) and the function would do it's thing -- anything like that?
> >
> > Thanks
> >
> > tedd
> >
> > --- Rob's suggestion follows.
> >
> > Like the following?
> >
> > <?php
> >
> > function f_a()
> > {
> > echo 'a';
> > }
> >
> > function f_b()
> > {
> > echo 'b';
> > }
> >
> > function f_c()
> > {
> > echo 'c';
> > }
> >
> > $map = array
> > (
> > 'a' => 'f_a',
> > 'b' => 'f_b',
> > 'c' => 'f_c',
> > );
> >
> > $map['a']();
> > $map['b']();
> > $map['c']();
> >
> > ?>
> >
> >
> > --
> > -------------------------------------------------------------------------
> >------- http://sperling.com
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> Like Music?
> http://l-i-e.com/artists.htm

I believe you're thinking more of the C++ style of returning by reference.
This article should help explain how references work, and how to return
references... most specifically check the "Returning References" section.

http://www.php.net/manual/en/language.references.php

HTH
--
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
www.americanstudentloan.com
1.800.575.1099

attached mail follows:


>
> I believe you're thinking more of the C++ style of returning by reference.
> This article should help explain how references work, and how to return
> references... most specifically check the "Returning References" section.
>
> http://www.php.net/manual/en/language.references.php
>
> HTH
> --
> Ray Hauge
> Programmer/Systems Administrator
> American Student Loan Services
> www.americanstudentloan.com
> 1.800.575.1099

nevermind... I what I read and what was actually written seem to have been two
entirely different things ;) Still good info though.

--
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
www.americanstudentloan.com
1.800.575.1099

attached mail follows:


If you want to serve .xml files as php, make the relevant change in the
http.conf file (if you are using apache).

On 10/04/06, Michael Crute <mcrutegmail.com> wrote:
>
> On 4/10/06, Robbert van Andel <phpswimwebs.com> wrote:
> > First off, and I'm sorry that this isn't a PHP specific question, but
> does
> > RSS require an XML extension? And if it does, how do I get the server
> to
> > serve the PHP file correctly if I rename it with the xml extension?
>
> No, you can use any extension you like for the RSS document, including
> .php its the contents that matters.
>
> -Mike
>
>
> --
> ________________________________
> Michael E. Crute
> http://mike.crute.org
>
> It is a mistake to think you can solve any major problems just with
> potatoes.
> --Douglas Adams
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
http://www.web-buddha.co.uk
dynamic web programming from Reigate, Surrey UK

look out for e-karma, our new venture, coming soon!

attached mail follows:


Robbert,

maybe it is only a typo, but you have written:

"xml." not ".xml" (notice the position of the dot).

/frank
10 apr 2006 kl. 15.37 skrev Robbert van Andel:

> I am working on creating some RSS feeds on my website using PHP.
> I'm still
> learning RSS but it seems easy enough. I managed to create the RSS
> giving
> the file a PHP extension. When I tried saving it with an xml
> extension and
> adding a .htaccess file to the directory in which the file was
> saved, I get
> prompted to save the file instead of being able to view the file in a
> browser. The only line in the .htaccess file is AddType
> application/x-httpd-php xml.
>
>
>
> First off, and I'm sorry that this isn't a PHP specific question,
> but does
> RSS require an XML extension? And if it does, how do I get the
> server to
> serve the PHP file correctly if I rename it with the xml extension?
>
>
>
> Thanks,
>
> Robbert van Andel
>
>
>

attached mail follows:


Thanks. I had added the header to the file. If the php extension is good enough, then I am not going to worry about the .htaccess file.

>> ... When I tried saving it with an xml extension and
>> adding a .htaccess file to the directory in which the file was saved, I get
>> prompted to save the file instead of being able to view the file in a
>> browser. The only line in the .htaccess file is AddType
>> application/x-httpd-php xml.
>
>I had similar problems when trying to roll-my-own RSS feed with php.
>Michael is right that it doesn't matter what your file extension is
>(you probably don't even need that htaccess directive) as long as the
>file is served as XML. Try adding a header at the top of the file:
>
>header("Content-type: text/xml; charset=utf-8");
>
><rss version="2.0">
><channel>
>
>...
>
>I also use the Firefox browser which has a built-in XML browser that
>allows me to do a quick validation of the XML. You can also use
>www.feedvalidator.org to troubleshoot your feed once its online.
>
>- Greg
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>

attached mail follows:


Actually, the dot is the end of a sentence ... damn my excellnet grammar skills :)

In the htaccess file, I hadn't included a dot at either end of XML. I think I'm going to just leave the file extension as PHP and see how that goes.

Thanks,
Robbert

>Robbert,
>
>maybe it is only a typo, but you have written:
>
>"xml." not ".xml" (notice the position of the dot).
>
>/frank
>10 apr 2006 kl. 15.37 skrev Robbert van Andel:
>
>> I am working on creating some RSS feeds on my website using PHP.
>> I'm still
>> learning RSS but it seems easy enough. I managed to create the RSS
>> giving
>> the file a PHP extension. When I tried saving it with an xml
>> extension and
>> adding a .htaccess file to the directory in which the file was
>> saved, I get
>> prompted to save the file instead of being able to view the file in a
>> browser. The only line in the .htaccess file is AddType
>> application/x-httpd-php xml.
>>
>>
>>
>> First off, and I'm sorry that this isn't a PHP specific question,
>> but does
>> RSS require an XML extension? And if it does, how do I get the
>> server to
>> serve the PHP file correctly if I rename it with the xml extension?
>>
>>
>>
>> Thanks,
>>
>> Robbert van Andel
>>
>>
>>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>

attached mail follows:


On Mon, April 10, 2006 8:37 am, Robbert van Andel wrote:
> I am working on creating some RSS feeds on my website using PHP. I'm
> still
> learning RSS but it seems easy enough. I managed to create the RSS
> giving
> the file a PHP extension. When I tried saving it with an xml
> extension and
> adding a .htaccess file to the directory in which the file was saved,
> I get
> prompted to save the file instead of being able to view the file in a
> browser. The only line in the .htaccess file is AddType
> application/x-httpd-php xml.
>
> First off, and I'm sorry that this isn't a PHP specific question, but
> does
> RSS require an XML extension? And if it does, how do I get the server
> to
> serve the PHP file correctly if I rename it with the xml extension?

First off, check that httpd.conf is even USING .htaccess
You can find/read httpd.conf, or you can make a new directory with
index.html in it, surf to it, then put something totally bogus in an
.htaccess file in that directory.
If .htaccess is "on" then you'll get a 500 server error because of
your bogus .htaccess settings.

Next, you need to check WHAT you are allowed to override in .htaccess
For that, you'll have to actually read httpd.conf, if you can, or do a
LOT of experiments if your webhost has it non-readable. (My webhost
used to do that, but he got smarter)

If all else fails, you can do:

http://example.com/rss.php/whatever.xml

where rss.php is your REAL script, and whatever.xml is junk that
Apache and PHP will cheerfully ignore.

Actually, they don't TOTALLY ignore it, they store it in
$_SERVER['PATH_INFO'] for you, in case you need it.

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

attached mail follows:


On Mon, April 10, 2006 1:36 pm, phpswimwebs.com wrote:
> Thanks. I had added the header to the file. If the php extension is
> good enough, then I am not going to worry about the .htaccess file.

I'd be awful careful here...

SOME versions of Microsoft IE are particularly stoopid about dealing
with URLs and Content-type etc.

SOME versions are even more weird when you add GET parameters to non
HTML document URLs. E.G.
http://example.com/myphpscript.pdf?date=5/1/2006
Where myphpscript.pdf has been ForceType in .htaccess to be PHP.

If I was you, I'd still try for the .xml ending and don't give the web
browsers who might link to your RSS feed any opportunity to [bleep]
up.

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

attached mail follows:


Dear List,

I have been working with a PHP script that curls a file from another
server. This works fine on my local machine, but not on our live server.
The script takes about 400 seconds to execute completely. I was under the
impression that my call to set_time_limit(900); was helping. Well, I took
that line out and nothing changed locally or on the server. In fact I even
tried this little test:

<?php
// header include for my config (to get Util)
error_reporting(E_ALL);
echo '<br>max execution time: '. ini_get('max_execution_time');
sleep(40);
echo "<br>done!";
echo "<br><br>Script Executed Time: ". Util::displayMicroTime(
$_SCRIPT_START_TIME, Util::getMicroTime() );
die('<br>'.__FILE__.__LINE__);
?>

Outputs:
max execution time: 30
done!

Script Executed Time: 40.01
/Users/eric/Sites/test/member_get_update.php26

Now why did this work? Shouldn't the script have timed out after 30
seconds?

Thanks in advance!

Eric

attached mail follows:


On Monday 10 April 2006 11:30, Eric Butera wrote:
> Dear List,
>
> I have been working with a PHP script that curls a file from another
> server. This works fine on my local machine, but not on our live server.
> The script takes about 400 seconds to execute completely. I was under the
> impression that my call to set_time_limit(900); was helping. Well, I took
> that line out and nothing changed locally or on the server. In fact I even
> tried this little test:
>
> <?php
> // header include for my config (to get Util)
> error_reporting(E_ALL);
> echo '<br>max execution time: '. ini_get('max_execution_time');
> sleep(40);
> echo "<br>done!";
> echo "<br><br>Script Executed Time: ". Util::displayMicroTime(
> $_SCRIPT_START_TIME, Util::getMicroTime() );
> die('<br>'.__FILE__.__LINE__);
> ?>
>
>
> Outputs:
> max execution time: 30
> done!
>
> Script Executed Time: 40.01
> /Users/eric/Sites/test/member_get_update.php26
>
>
> Now why did this work? Shouldn't the script have timed out after 30
> seconds?
>
> Thanks in advance!
>
> Eric

The information in set_time_limit() might help:

http://us3.php.net/set_time_limit

"Note: The set_time_limit() function and the configuration directive
max_execution_time only affect the execution time of the script itself. Any
time spent on activity that happens outside the execution of the script such
as system calls using system(), stream operations, database queries, etc. is
not included when determining the maximum time that the script has been
running."

HTH

--
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
www.americanstudentloan.com
1.800.575.1099

attached mail follows:


On 4/10/06, Ray Hauge <ray.haugeamericanstudentloan.com> wrote:
>
> On Monday 10 April 2006 11:30, Eric Butera wrote:
> > Dear List,
> >
> > I have been working with a PHP script that curls a file from another
> > server. This works fine on my local machine, but not on our live
> server.
> > The script takes about 400 seconds to execute completely. I was under
> the
> > impression that my call to set_time_limit(900); was helping. Well, I
> took
> > that line out and nothing changed locally or on the server. In fact I
> even
> > tried this little test:
> >
> > <?php
> > // header include for my config (to get Util)
> > error_reporting(E_ALL);
> > echo '<br>max execution time: '. ini_get('max_execution_time');
> > sleep(40);
> > echo "<br>done!";
> > echo "<br><br>Script Executed Time: ". Util::displayMicroTime(
> > $_SCRIPT_START_TIME, Util::getMicroTime() );
> > die('<br>'.__FILE__.__LINE__);
> > ?>
> >
> >
> > Outputs:
> > max execution time: 30
> > done!
> >
> > Script Executed Time: 40.01
> > /Users/eric/Sites/test/member_get_update.php26
> >
> >
> > Now why did this work? Shouldn't the script have timed out after 30
> > seconds?
> >
> > Thanks in advance!
> >
> > Eric
>
> The information in set_time_limit() might help:
>
> http://us3.php.net/set_time_limit
>
> "Note: The set_time_limit() function and the configuration directive
> max_execution_time only affect the execution time of the script itself.
> Any
> time spent on activity that happens outside the execution of the script
> such
> as system calls using system(), stream operations, database queries, etc.
> is
> not included when determining the maximum time that the script has been
> running."
>
> HTH
>
> --
> Ray Hauge
> Programmer/Systems Administrator
> American Student Loan Services
> www.americanstudentloan.com
> 1.800.575.1099
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

Ray,

Thank you for your response. I did read that in the manual, I promise.
That is why I included the sleep function in my example. Shouldn't the
sleep function count as execution time? One thing I didn't metion earlier,
for the sake of simplicity, is that my script is pulling an XML file. After
I get the XML file I parse through it which also takes time too. The
recordset is about 6 thousand records so it does take a while.

attached mail follows:


On Monday 10 April 2006 11:48, Eric Butera wrote:
> Ray,
>
> Thank you for your response. I did read that in the manual, I promise.
> That is why I included the sleep function in my example. Shouldn't the
> sleep function count as execution time? One thing I didn't metion earlier,
> for the sake of simplicity, is that my script is pulling an XML file.
> After I get the XML file I parse through it which also takes time too. The
> recordset is about 6 thousand records so it does take a while.

Right after I sent that I started wondering if sleep() would be counted in the
time or not. I would think it would, but it *could* in the background just
run the system sleep, which might not be counted... I don't know that much
about the sleep function to tell you. Parsing the XML should cause it to
time out if it was longer than 9 seconds though... interesting situation...

At the moment I don't have much else for you :(

--
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
www.americanstudentloan.com
1.800.575.1099

attached mail follows:


On Mon, April 10, 2006 1:48 pm, Eric Butera wrote:
> Thank you for your response. I did read that in the manual, I
> promise.
> That is why I included the sleep function in my example. Shouldn't
> the
> sleep function count as execution time? One thing I didn't metion
> earlier,
> for the sake of simplicity, is that my script is pulling an XML file.
> After
> I get the XML file I parse through it which also takes time too. The
> recordset is about 6 thousand records so it does take a while.

'sleep' doesn't count.

That's even in the 3rd to last User Contributed Note. :-)

Always read the Notes. You may have to wade through some [bleep] but
you'll find some nuggets of info well worth the effort.

The primary goal of set_time_limit is to keep scripts from slamming
the server and taking ALL the CPU time.

If the script is sleeping, it's not taking CPU time.

I missed the beginning of the thread, but if you need to count 'sleep'
time, you'll just have to code it yourself somehow...

I suppose the first item on your agenda might be to contribute a
get_time_spent() function to the PHP source that returned whatever
value PHP is using to track this CPU usage. :-)

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

attached mail follows:


Hello all,

My website uses simpleXML to print the headlines from a few different RSS
feeds. The problem is that sometimes the remote feed is unavailable if there
are problems with the remote site, and the result is that I must wait for 30
seconds or so until the HTTP timeout occurs, delaying the rendering of my
site.

So far, I have moved the code that grabs the RSS feeds to the bottom of my
page, so that the main page content is rendered first, but this is only a
partial solution.

Is there a way to give the simplexml_load_file() a 5 second timeout before
giving up and moving on?

Here is my function:

function getFeed($remote) {
    if (!$xml = simplexml_load_file($remote)) {
        print "Feed unavailable";
        return;
    }
    print "<ul>\n";
    foreach ($xml->channel->item as $item) {
        $cleaned = str_replace("&", "&amp;", $item->link);
        print "<li><a href='$cleaned'>$item->title</a></li>\n";
    }
    print "</ul>\n";
}

PHP 5.1.2 on Linux.
thanks,
-d
--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

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

iD8DBQBEOrFBwPD5Cr/3CJgRAs6dAKCkV89bBBgtBLEH7cJS1MA9AQnfFQCgv/q4
MLdZmSd14muvkpGJpB/VRQQ=
=P0uI
-----END PGP SIGNATURE-----

attached mail follows:


On Mon, 2006-04-10 at 15:25, darren kirby wrote:
> Hello all,
>
> My website uses simpleXML to print the headlines from a few different RSS
> feeds. The problem is that sometimes the remote feed is unavailable if there
> are problems with the remote site, and the result is that I must wait for 30
> seconds or so until the HTTP timeout occurs, delaying the rendering of my
> site.
>
> So far, I have moved the code that grabs the RSS feeds to the bottom of my
> page, so that the main page content is rendered first, but this is only a
> partial solution.
>
> Is there a way to give the simplexml_load_file() a 5 second timeout before
> giving up and moving on?
>
> Here is my function:
>
> function getFeed($remote) {
> if (!$xml = simplexml_load_file($remote)) {
> print "Feed unavailable";
> return;
> }
> print "<ul>\n";
> foreach ($xml->channel->item as $item) {
> $cleaned = str_replace("&", "&amp;", $item->link);
> print "<li><a href='$cleaned'>$item->title</a></li>\n";
> }
> print "</ul>\n";
> }

Why do you do this on every request? Why not have a cron job retrieve an
update every 20 minutes or whatnot and stuff it into a database table
for your page to access? Then if the cron fails to retrieve the feed it
can just leave the table as is, and your visitors can happily view
slightly outdated feeds? Additionally this will be so much faster that
your users might even hang around on your site :)

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

attached mail follows:


quoth the Robert Cummings:
>
> Why do you do this on every request? Why not have a cron job retrieve an
> update every 20 minutes or whatnot and stuff it into a database table
> for your page to access? Then if the cron fails to retrieve the feed it
> can just leave the table as is, and your visitors can happily view
> slightly outdated feeds? Additionally this will be so much faster that
> your users might even hang around on your site :)

This is a very interesting idea, but I am not sure if it is suitable for me at
this point. First of all, one feed in particular can change in a matter of
seconds, and I do want it to be as up to date as possible. Secondly, this is
just for my personal site which is very low traffic, and it is not
inconceivable that getting the feed every 20 minutes by cron would be _more_
taxing on the network than simply grabbing it per request...

And to be fair, when everything is working as it should the feeds are
retrieved in a matter of seconds, and I don't think it is annoying my users
at all. It is the 0.5% of requests when the remote site is overloaded (or
just plain down) that I want to provision for here.

I do like this idea of caching the feed though. I think in my situation
though, rather than prefetching the feed at regular intervals it may be
better to cache the most recent request, and check the age of the cache when
the next request comes. This way, I would not be needlessly updating it for
those times when the page with my feeds goes for a few hours without a
request.

Of course, this still wouldn't solve my original problem.

> Cheers,
> Rob.
> --

Thanks for your insight,
-d
--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

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

iD8DBQBEOtI2wPD5Cr/3CJgRAvXkAKC+yH9+CSbd9huu3xZmso5XDrIoEwCfYFYo
ceFiwgtxW0LNU7jO9tezTmQ=
=FGhA
-----END PGP SIGNATURE-----

attached mail follows:


On Mon, 2006-04-10 at 17:46, darren kirby wrote:
> quoth the Robert Cummings:
> >
> > Why do you do this on every request? Why not have a cron job retrieve an
> > update every 20 minutes or whatnot and stuff it into a database table
> > for your page to access? Then if the cron fails to retrieve the feed it
> > can just leave the table as is, and your visitors can happily view
> > slightly outdated feeds? Additionally this will be so much faster that
> > your users might even hang around on your site :)
>
> This is a very interesting idea, but I am not sure if it is suitable for me at
> this point. First of all, one feed in particular can change in a matter of
> seconds, and I do want it to be as up to date as possible. Secondly, this is
> just for my personal site which is very low traffic, and it is not
> inconceivable that getting the feed every 20 minutes by cron would be _more_
> taxing on the network than simply grabbing it per request...
>
> And to be fair, when everything is working as it should the feeds are
> retrieved in a matter of seconds, and I don't think it is annoying my users
> at all. It is the 0.5% of requests when the remote site is overloaded (or
> just plain down) that I want to provision for here.
>
> I do like this idea of caching the feed though. I think in my situation
> though, rather than prefetching the feed at regular intervals it may be
> better to cache the most recent request, and check the age of the cache when
> the next request comes. This way, I would not be needlessly updating it for
> those times when the page with my feeds goes for a few hours without a
> request.
>
> Of course, this still wouldn't solve my original problem.

Well personal websites break all the rules. There's nobody to answer to
but yourself :)

Looks like simplexml neglected to offer a timeout option. You would
probably be better off using curl to retrieve the content, then using
simplexml_load_string(). Curl does allow you to assign a timeout.

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

attached mail follows:


quoth the Robert Cummings:
> On Mon, 2006-04-10 at 17:46, darren kirby wrote:
> > quoth the Robert Cummings:
> > > Why do you do this on every request? Why not have a cron job retrieve
> > > an update every 20 minutes or whatnot and stuff it into a database
> > > table for your page to access? Then if the cron fails to retrieve the
> > > feed it can just leave the table as is, and your visitors can happily
> > > view slightly outdated feeds? Additionally this will be so much faster
> > > that your users might even hang around on your site :)
> >
> > This is a very interesting idea, but I am not sure if it is suitable for
> > me at this point. First of all, one feed in particular can change in a
> > matter of seconds, and I do want it to be as up to date as possible.
> > Secondly, this is just for my personal site which is very low traffic,
> > and it is not inconceivable that getting the feed every 20 minutes by
> > cron would be _more_ taxing on the network than simply grabbing it per
> > request...
> >
> > And to be fair, when everything is working as it should the feeds are
> > retrieved in a matter of seconds, and I don't think it is annoying my
> > users at all. It is the 0.5% of requests when the remote site is
> > overloaded (or just plain down) that I want to provision for here.
> >
> > I do like this idea of caching the feed though. I think in my situation
> > though, rather than prefetching the feed at regular intervals it may be
> > better to cache the most recent request, and check the age of the cache
> > when the next request comes. This way, I would not be needlessly updating
> > it for those times when the page with my feeds goes for a few hours
> > without a request.
> >
> > Of course, this still wouldn't solve my original problem.
>
> Well personal websites break all the rules. There's nobody to answer to
> but yourself :)
>
> Looks like simplexml neglected to offer a timeout option. You would
> probably be better off using curl to retrieve the content, then using
> simplexml_load_string(). Curl does allow you to assign a timeout.

That's the ticket! Thanks a lot for your help.

> Cheers,
> Rob.

-d

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

--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

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

iD8DBQBEOtuXwPD5Cr/3CJgRAgLLAKCwBr0EoEEWTOP07zHpU2LpcsjjrQCeOzUC
ECO1teFNhaihC4wklD+p5fo=
=7D+w
-----END PGP SIGNATURE-----

attached mail follows:


Maybe you can read the contents of the feeds using fsockopen() and
stream_set_timeout() to adjust the timeout, or stream_set_blocking()
to read it asynchronously, and then load the xml with
simplexml_load_string().

PS: I forgot to reply to all and mention you'll have to send the GET
http command and headers, check the php manual for examples.

2006/4/10, darren kirby <bulliverbadcomputer.org>:
> Hello all,
>
> My website uses simpleXML to print the headlines from a few different RSS
> feeds. The problem is that sometimes the remote feed is unavailable if there
> are problems with the remote site, and the result is that I must wait for 30
> seconds or so until the HTTP timeout occurs, delaying the rendering of my
> site.
>
> So far, I have moved the code that grabs the RSS feeds to the bottom of my
> page, so that the main page content is rendered first, but this is only a
> partial solution.
>
> Is there a way to give the simplexml_load_file() a 5 second timeout before
> giving up and moving on?
>
> Here is my function:
>
> function getFeed($remote) {
> if (!$xml = simplexml_load_file($remote)) {
> print "Feed unavailable";
> return;
> }
> print "<ul>\n";
> foreach ($xml->channel->item as $item) {
> $cleaned = str_replace("&", "&amp;", $item->link);
> print "<li><a href='$cleaned'>$item->title</a></li>\n";
> }
> print "</ul>\n";
> }
>
> PHP 5.1.2 on Linux.
> thanks,
> -d
> --
> darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
> "...the number of UNIX installations has grown to 10, with more expected..."
> - Dennis Ritchie and Ken Thompson, June 1972
>
>
>

attached mail follows:


quoth the Martin Alterisio:
> Maybe you can read the contents of the feeds using fsockopen() and
> stream_set_timeout() to adjust the timeout, or stream_set_blocking()
> to read it asynchronously, and then load the xml with
> simplexml_load_string().

Hello, and thanks for the response,

As Robert Cummings suggested above, the easy solution is to use curl, which
does offer a timeout option, and then feed it to simplexml_load_string().

I am writing some code now...

Thanks, and have a good one,
-d

--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

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

iD8DBQBEOt0NwPD5Cr/3CJgRAqahAKDoCH4BwUVanRMHadLPz1jeY4GikwCg7mxg
TkPmQ56OrzJACq3DUG0Zt2o=
=n2rx
-----END PGP SIGNATURE-----

attached mail follows:


Martin Alterisio wrote:
> Maybe you can read the contents of the feeds using fsockopen() and
> stream_set_timeout() to adjust the timeout, or stream_set_blocking()
> to read it asynchronously, and then load the xml with
> simplexml_load_string().
>
> PS: I forgot to reply to all and mention you'll have to send the GET
> http command and headers, check the php manual for examples.

You can just use fopen() to avoid all that.

eg.

$fd = fopen($url);
stream_set_blocking($fd,true);
stream_set_timeout($fd, 5); // 5-second timeout
$data = stream_get_contents($fd);
$status = stream_get_meta_data($fd);
if($status['timed_out']) echo "Time out";
else {
   $xml = simplexml_load_string($data);
}

As for your caching, make sure you create the cache file atomically. So
how about this:

function request_cache($url, $dest_file, $ctimeout=60, $rtimeout=5) {
   if(!file_exists($dest_file) || filemtime($dest_file) <
(time()-$ctimeout)) {
     $stream = fopen($url,'r');
     stream_set_blocking($stream,true);
     stream_set_timeout($stream, $rtimeout);
     $tmpf = tempnam('/tmp','YWS');
     file_put_contents($tmpf, $stream);
     fclose($stream);
     rename($tmpf, $dest_file);
   }
}

That takes the url to your feed, a destination file to cache to, a cache
timeout (as in, fetch from the feed if the cache is older than 60
seconds) and finally the request timeout.

Note the file_put_contents of the stream straight to disk, so you don't
ever suck the file into memory. You can then use a SAX parser like
xmlreader on it and your memory usage will be minimal. You will need
PHP 5.1.x for this to work.

You could also use apc_store/fetch and skip the disk copy altogether.

(untested and typed up during a long boring meeting, so play with it a bit)

-Rasmus

attached mail follows:


On Mon, April 10, 2006 4:46 pm, darren kirby wrote:
> quoth the Robert Cummings:
>>
>> Why do you do this on every request? Why not have a cron job
>> retrieve an
>> update every 20 minutes or whatnot and stuff it into a database
>> table
>> for your page to access? Then if the cron fails to retrieve the feed
>> it
>> can just leave the table as is, and your visitors can happily view
>> slightly outdated feeds? Additionally this will be so much faster
>> that
>> your users might even hang around on your site :)
>
> This is a very interesting idea, but I am not sure if it is suitable
> for me at
> this point. First of all, one feed in particular can change in a
> matter of
> seconds, and I do want it to be as up to date as possible. Secondly,
> this is
> just for my personal site which is very low traffic, and it is not
> inconceivable that getting the feed every 20 minutes by cron would be
> _more_
> taxing on the network than simply grabbing it per request...

Perhaps, then, you should:
maintain a list of URLs and acceptable "age" of feed.
Attempt to snag the new content upon visit, if the content is "old"
Show the "old" content if the feed takes longer than X seconds.

You'll STILL need a timeout, which, unfortunately, means you are stuck
rolling your own solution with http://php.net/fsockopen because all
the "simple" solutions pretty much suck in terms of network timeout.
:-(

It would be REALLY NIFTY if fopen and friends which understand all
those protocols of HTTP FTP HTTPS and so on, allowed one to set a
timeout for URLs, but they don't and nobody with the skills to change
that (not me) seems even mildly interested. :-( :-( :-(

Since I've already written a class that does something like what you
want, or maybe even exactly what you want, I might as well just
provide the source, eh?

http://l-i-e.com/FeedMulti/FeedMulti.phps

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

attached mail follows:


On Mon, April 10, 2006 6:17 pm, Rasmus Lerdorf wrote:
> Martin Alterisio wrote:
>> Maybe you can read the contents of the feeds using fsockopen() and
>> stream_set_timeout() to adjust the timeout, or stream_set_blocking()
>> to read it asynchronously, and then load the xml with
>> simplexml_load_string().
>>
>> PS: I forgot to reply to all and mention you'll have to send the GET
>> http command and headers, check the php manual for examples.
>
> You can just use fopen() to avoid all that.

No, he can't.

Sorry, Rasmus. :-)

If the URL is not working at the time of fopen() then you'll sit there
spinning your wheels waiting for fopen() itself to timeout, before you
ever GET a valid file handle to which one can apply stream_set_timeout
and/or stream_set_blocking.

That can take MUCH too long.

So you're STUCK with fsockopen, which DOES take a timeout parameter
for OPENING the socket, as well as giving one a stream to which
stream_set_blocking and stream_set_timeout can be applied.

But then you are stuck re-inventing the damn wheel with any protocol
you'd like to support like GET/POST, HTTPS (ugh!), FTP and so on.

All of which is buried in the guts of the Truly Nifty fopen,
file_get_contents, and so forth, but is utterly useless if you care at
all about timing out in a reasonably-responsive application.

So you have do all the junk to send things like:
GET / HTTP/1.0
Host: example.com
yourself, and God help you if you want to support HTTPS.

Actually, curl MAY be the better solution -- but my boss doesn't have
curl installed, so I was screwed anyway...

This is why I (and others) have put in a Feature Request to get
fopen() and friends to have some kind of programmatically changable
timeout setting. Said Feature Requests invariably get marked "Bogus"
and then commented with something like the non-solution above. :-)

Oh well.

It *can* be done; You just have to type WAY too much junk to do
something very simple and very commonly needed.

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

attached mail follows:


quoth the Richard Lynch:
> Perhaps, then, you should:
> maintain a list of URLs and acceptable "age" of feed.
> Attempt to snag the new content upon visit, if the content is "old"
> Show the "old" content if the feed takes longer than X seconds.

I really do like this idea, as I would rather use an old feed than just print
"Feed unavailable" as I have it now.

> You'll STILL need a timeout, which, unfortunately, means you are stuck
> rolling your own solution with http://php.net/fsockopen because all
> the "simple" solutions pretty much suck in terms of network timeout.
>
> :-(
>
> It would be REALLY NIFTY if fopen and friends which understand all
> those protocols of HTTP FTP HTTPS and so on, allowed one to set a
> timeout for URLs, but they don't and nobody with the skills to change
> that (not me) seems even mildly interested. :-( :-( :-(

I am interested, but I don't have the skills either...

> Since I've already written a class that does something like what you
> want, or maybe even exactly what you want, I might as well just
> provide the source, eh?
>
> http://l-i-e.com/FeedMulti/FeedMulti.phps

Thanks for that, it looks like interesting code, if not a little over my head.
I am just a duffer here. I will certainly play with it some more. As for
curl, I realized I didn't add curl support myself, so I am rebuilding PHP
now...

When I do get something figured out I will post results here. Problem is, with
either method I need to find a feed that is slow to test with. If I test it
with a bunk url it will just 404 immediately right? Is there a way to
simulate a slow connection?

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

Thanks a lot for the help, everybody!
-d
--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

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

iD8DBQBEOv3PwPD5Cr/3CJgRAh76AJ48GyrRl/lbfGAfotOGRmz+dP7WXwCcDXNa
EtSB6l3C3gdv3/OnpSks32c=
=gNnC
-----END PGP SIGNATURE-----

attached mail follows:


On Mon, 2006-04-10 at 20:52, darren kirby wrote:
> quoth the Richard Lynch:
> > Perhaps, then, you should:
> > maintain a list of URLs and acceptable "age" of feed.
> > Attempt to snag the new content upon visit, if the content is "old"
> > Show the "old" content if the feed takes longer than X seconds.
>
> I really do like this idea, as I would rather use an old feed than just print
> "Feed unavailable" as I have it now.
>
> > You'll STILL need a timeout, which, unfortunately, means you are stuck
> > rolling your own solution with http://php.net/fsockopen because all
> > the "simple" solutions pretty much suck in terms of network timeout.
> >
> > :-(
> >
> > It would be REALLY NIFTY if fopen and friends which understand all
> > those protocols of HTTP FTP HTTPS and so on, allowed one to set a
> > timeout for URLs, but they don't and nobody with the skills to change
> > that (not me) seems even mildly interested. :-( :-( :-(
>
> I am interested, but I don't have the skills either...
>
> > Since I've already written a class that does something like what you
> > want, or maybe even exactly what you want, I might as well just
> > provide the source, eh?
> >
> > http://l-i-e.com/FeedMulti/FeedMulti.phps
>
> Thanks for that, it looks like interesting code, if not a little over my head.
> I am just a duffer here. I will certainly play with it some more. As for
> curl, I realized I didn't add curl support myself, so I am rebuilding PHP
> now...
>
> When I do get something figured out I will post results here. Problem is, with
> either method I need to find a feed that is slow to test with. If I test it
> with a bunk url it will just 404 immediately right? Is there a way to
> simulate a slow connection?

For sure ;) Pull your ethernet cable out. Doesn't get much slower :D

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

attached mail follows:


> When I do get something figured out I will post results here. Problem
> is, with
> either method I need to find a feed that is slow to test with. If I
> test it
> with a bunk url it will just 404 immediately right? Is there a way to
> simulate a slow connection?

I dunno about similating a slow connection, but you can write a very
slow server... :-)

my_slow_rss_feed.php
<?php
  $data = '<name>Darren Kirby</name>';
  sleep(10);
  for ($i = 0; $i < strlen($data); $i++){
    echo $data[$i];
    flush();
    sleep(1);
  }
?>

Of course, that doesn't simulate the slow connection part of it...

If you have 2 machines, you can unplug the network cable, start your
script, then plug the cable in after 5 seconds.

That's gonna make it pretty slow to connect, almost for sure. :-)

If anybody is goofy enough to complain about the performance of
strlen() in the for(...) statement, you're clearly not paying
attention. :-) :-) :-)

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

attached mail follows:


Maybe it's too late to say this, but if your real problem is that you
don't want the function reading
the rss feed to block the rest of your page, you can always put the
output of the reading of the feed
on a separate page, and include this through an iframe.

darren kirby wrote:

>Hello all,
>
>My website uses simpleXML to print the headlines from a few different RSS
>feeds. The problem is that sometimes the remote feed is unavailable if there
>are problems with the remote site, and the result is that I must wait for 30
>seconds or so until the HTTP timeout occurs, delaying the rendering of my
>site.
>
>So far, I have moved the code that grabs the RSS feeds to the bottom of my
>page, so that the main page content is rendered first, but this is only a
>partial solution.
>
>Is there a way to give the simplexml_load_file() a 5 second timeout before
>giving up and moving on?
>
>Here is my function:
>
>function getFeed($remote) {
> if (!$xml = simplexml_load_file($remote)) {
> print "Feed unavailable";
> return;
> }
> print "<ul>\n";
> foreach ($xml->channel->item as $item) {
> $cleaned = str_replace("&", "&amp;", $item->link);
> print "<li><a href='$cleaned'>$item->title</a></li>\n";
> }
> print "</ul>\n";
>}
>
>PHP 5.1.2 on Linux.
>thanks,
>-d
>
>

attached mail follows:


Richard Lynch wrote:
> On Mon, April 10, 2006 6:17 pm, Rasmus Lerdorf wrote:
>> Martin Alterisio wrote:
>>> Maybe you can read the contents of the feeds using fsockopen() and
>>> stream_set_timeout() to adjust the timeout, or stream_set_blocking()
>>> to read it asynchronously, and then load the xml with
>>> simplexml_load_string().
>>>
>>> PS: I forgot to reply to all and mention you'll have to send the GET
>>> http command and headers, check the php manual for examples.
>> You can just use fopen() to avoid all that.
>
> No, he can't.
>
> Sorry, Rasmus. :-)
>
> If the URL is not working at the time of fopen() then you'll sit there
> spinning your wheels waiting for fopen() itself to timeout, before you
> ever GET a valid file handle to which one can apply stream_set_timeout
> and/or stream_set_blocking.

I thought it was the case of an overloaded slow-responding server, not
one that is down. For the initial connection just set your
default_socket_timeout appropriately if you are not happy with the default.

So you just add 1 line to my example:

function request_cache($url, $dest_file, $ctimeout=60, $rtimeout=5) {
   if(!file_exists($dest_file) || filemtime($dest_file) <
(time()-$ctimeout)) {
     ini_set('default_socket_timeout',$rtimeout);
     $stream = fopen($url,'r');
     stream_set_blocking($stream,true);
     stream_set_timeout($stream, $rtimeout);
     $tmpf = tempnam('/tmp','YWS');
     file_put_contents($tmpf, $stream);
     fclose($stream);
     rename($tmpf, $dest_file);
   }
}

Problem solved.

-Rasmus

attached mail follows:


Richard Lynch wrote:
> It would be REALLY NIFTY if fopen and friends which understand all
> those protocols of HTTP FTP HTTPS and so on, allowed one to set a
> timeout for URLs, but they don't and nobody with the skills to change
> that (not me) seems even mildly interested. :-( :-( :-(

Because it is already there and has been since Sept.23 2002 when it was
added.

-Rasmus

attached mail follows:


On Mon, April 10, 2006 9:59 pm, Rasmus Lerdorf wrote:
> Richard Lynch wrote:
>> It would be REALLY NIFTY if fopen and friends which understand all
>> those protocols of HTTP FTP HTTPS and so on, allowed one to set a
>> timeout for URLs, but they don't and nobody with the skills to
>> change
>> that (not me) seems even mildly interested. :-( :-( :-(
>
> Because it is already there and has been since Sept.23 2002 when it
> was
> added.

I've added a Note to 'fopen' so maybe others won't completely miss
this feature and look as foolish as I do right now. :-)

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

attached mail follows:


Richard Lynch wrote:
> On Mon, April 10, 2006 4:46 pm, darren kirby wrote:
>> quoth the Robert Cummings:
>>> Why do you do this on every request? Why not have a cron job
>>> retrieve an
>>> update every 20 minutes or whatnot and stuff it into a database
>>> table
>>> for your page to access? Then if the cron fails to retrieve the feed
>>> it
>>> can just leave the table as is, and your visitors can happily view
>>> slightly outdated feeds? Additionally this will be so much faster
>>> that
>>> your users might even hang around on your site :)
>> This is a very interesting idea, but I am not sure if it is suitable
>> for me at
>> this point. First of all, one feed in particular can change in a
>> matter of
>> seconds, and I do want it to be as up to date as possible. Secondly,
>> this is
>> just for my personal site which is very low traffic, and it is not
>> inconceivable that getting the feed every 20 minutes by cron would be
>> _more_
>> taxing on the network than simply grabbing it per request...
>
> Perhaps, then, you should:
> maintain a list of URLs and acceptable "age" of feed.
> Attempt to snag the new content upon visit, if the content is "old"
> Show the "old" content if the feed takes longer than X seconds.
>
> You'll STILL need a timeout, which, unfortunately, means you are stuck
> rolling your own solution with http://php.net/fsockopen because all
> the "simple" solutions pretty much suck in terms of network timeout.
> :-(
>
> It would be REALLY NIFTY if fopen and friends which understand all
> those protocols of HTTP FTP HTTPS and so on, allowed one to set a
> timeout for URLs, but they don't and nobody with the skills to change
> that (not me) seems even mildly interested. :-( :-( :-(
>
> Since I've already written a class that does something like what you
> want, or maybe even exactly what you want, I might as well just
> provide the source, eh?
>
> http://l-i-e.com/FeedMulti/FeedMulti.phps

No stream_select() ?

Here is an example Wez wrote years ago:

<?php
$hosts = array("host1.sample.com", "host2.sample.com", "host3.sample.com");
$timeout = 15;
$status = array();
$sockets = array();

/* Initiate connections to all the hosts simultaneously */
foreach ($hosts as $id => $host) {
        $s = stream_socket_client("$host:80", $errno, $errstr, $timeout,
                STREAM_CLIENT_ASYNC_CONNECT);

        if ($s) {
                $sockets[$id] = $s;
                $status[$id] = "in progress";
        } else {
                $status[$id] = "failed, $errno $errstr";
        }
}

/* Now, wait for the results to come back in */
while (count($sockets)) {
        $read = $write = $sockets;
        /* This is the magic function - explained below */
        $n = stream_select($read, $write, $e = null, $timeout);

        if ($n > 0) {
                /* readable sockets either have data for us, or are failed
                 * connection attempts */
                foreach ($read as $r) {
                        $id = array_search($r, $sockets);
                        $data = fread($r, 8192);
                        if (strlen($data) == 0) {
                                if ($status[$id] == "in progress") {
                                        $status[$id] = "failed to connect";
                                }
                                fclose($r);
                                unset($sockets[$id]);
                        } else {
                                $status[$id] .= $data;
                        }
                }
                /* writeable sockets can accept an HTTP request */
                foreach ($write as $w) {
                        $id = array_search($w, $sockets);
                        fwrite($w, "HEAD / HTTP/1.0\r\nHost: "
                                . $hosts[$id] . "\r\n\r\n");
                        $status[$id] = "waiting for response";
                }
        } else {
                /* timed out waiting; assume that all hosts associated
                 * with $sockets are faulty */
                foreach ($sockets as $id => $s) {
                        $status[$id] = "timed out " . $status[$id];
                }
                break;
        }
}

foreach ($hosts as $id => $host) {
        echo "Host: $host\n";
        echo "Status: " . $status[$id] . "\n\n";
}
?>

attached mail follows:


On Mon, 2006-04-10 at 23:11, Richard Lynch wrote:
> On Mon, April 10, 2006 9:59 pm, Rasmus Lerdorf wrote:
> > Richard Lynch wrote:
> >> It would be REALLY NIFTY if fopen and friends which understand all
> >> those protocols of HTTP FTP HTTPS and so on, allowed one to set a
> >> timeout for URLs, but they don't and nobody with the skills to
> >> change
> >> that (not me) seems even mildly interested. :-( :-( :-(
> >
> > Because it is already there and has been since Sept.23 2002 when it
> > was
> > added.
>
> I've added a Note to 'fopen' so maybe others won't completely miss
> this feature and look as foolish as I do right now. :-)

If it's anything like the helpful note I added about using copy( source,
dest ) where dest accidentally points to source (due to linking), you'll
get a nice retarded email like the following:

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

You are receiving this email because your note posted
to the online PHP manual has been removed by one of the editors.

Read the following paragraphs carefully, because they contain
pointers to resources better suited for requesting support or
reporting bugs, none of which are to be included in manual notes
because there are mechanisms and groups in place to deal with
those issues.

The user contributed notes are not an appropriate place to
ask questions, report bugs or suggest new features; please
use the resources listed on <http://php.net/support>
for those purposes. This was clearly stated in the page
you used to submit your note, please carefully re-read
those instructions before submitting future contributions.

Bug submissions and feature requests should be entered at
<http://bugs.php.net/>. For documentation errors use the
bug system, and classify the bug as "Documentation problem".
Support and ways to find answers to your questions can be found
at <http://php.net/support>.

Your note has been removed from the online manual.

----- Copy of your note below -----

User tip... it can be completely befuddling if you don't realize your
source and destination files are the same (this can happen with
directory links). When this happens there are a couple of
possibilities... at first I was using php 4.4.0 and the files just
became 0 length. The second, outcome after I upgraded to 4.4.2 (since I
didn't realize the problem) was that the copy function returned a
failure. This was tricky to track since there's no error output
indicating why the copy failed :)

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

attached mail follows:


Robert Cummings wrote:
> On Mon, 2006-04-10 at 23:11, Richard Lynch wrote:
>> On Mon, April 10, 2006 9:59 pm, Rasmus Lerdorf wrote:
>>> Richard Lynch wrote:
>>>> It would be REALLY NIFTY if fopen and friends which understand all
>>>> those protocols of HTTP FTP HTTPS and so on, allowed one to set a
>>>> timeout for URLs, but they don't and nobody with the skills to
>>>> change
>>>> that (not me) seems even mildly interested. :-( :-( :-(
>>> Because it is already there and has been since Sept.23 2002 when it
>>> was
>>> added.
>> I've added a Note to 'fopen' so maybe others won't completely miss
>> this feature and look as foolish as I do right now. :-)
>
> If it's anything like the helpful note I added about using copy( source,
> dest ) where dest accidentally points to source (due to linking), you'll
> get a nice retarded email like the following:

You could volunteer to help maintain the user notes. It it thankless
and tedious work to keep up with the flood of user notes being
submitted. A huge percentage of them being either spam, product pitches
or really dumb questions. The fact that occasionally a useful note gets
deleted by mistake doesn't surprise me.

-Rasmus

attached mail follows:


On Mon, 2006-04-10 at 23:35, Rasmus Lerdorf wrote:
> Robert Cummings wrote:
>
> >
> > I'll keep that in mind for the future when I have more free time (2 kids
> > under 3 is good for keeping me occupied beyond work atm :).
> >
> >> A huge percentage of them being either spam, product pitches
> >> or really dumb questions. The fact that occasionally a useful note gets
> >> deleted by mistake doesn't surprise me.
> >
> > Point taken, just sort of feels like slap in the face after you go to
> > the effort to write a useful note :)
>
> Yes, but just keep in mind that the folks on the other end make the
> effort every single day to cull through hundreds of these. We have
> small kids and real jobs as well. I am typing this with a 4-year old
> sitting in my lap doing his best to make a dinosaur stomp on my keys.

Ummm, that was a sincere "I'll keep it in mind". And I know all about
typing away with a newborn sleeping on my chest, a 1 year old pawing the
screen, a 2 year old mashing the keys and cackling mischievously.

> So while I sympathize with the fact that the work you put into this note
> wasn't appreciated, please recognize that you are not being very
> appreciative of the hundreds of hours of work the folks on the other end
> are putting in.

I'm very appreciative, but at the same time, I don't feel like I
shouldn't comment on the potential of getting your note trashed like so
much spam. Don't forget, adding a note IS contributing. I usually add as
I see fit, I've added in the past, I'm sure I'll add in the future. But
now I'm a little on the twice shy side of the coin.

> In general the user notes in the manual are useful.
> There isn't much spam, and when something slips through it gets caught
> rather quickly. This stuff doesn't happen by itself.

Exactly, it doesn't happen by itself, neither do the notes. It's a
dovetailing arrangement. People add notes, people trim spam. It takes
both for either system to work. Agreed, though that adding notes isn't
the same as spending countless hours pruning.

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

attached mail follows:


On Mon, 2006-04-10 at 23:24, Rasmus Lerdorf wrote:
> Robert Cummings wrote:
> > On Mon, 2006-04-10 at 23:11, Richard Lynch wrote:
> >> On Mon, April 10, 2006 9:59 pm, Rasmus Lerdorf wrote:
> >>> Richard Lynch wrote:
> >>>> It would be REALLY NIFTY if fopen and friends which understand all
> >>>> those protocols of HTTP FTP HTTPS and so on, allowed one to set a
> >>>> timeout for URLs, but they don't and nobody with the skills to
> >>>> change
> >>>> that (not me) seems even mildly interested. :-( :-( :-(
> >>> Because it is already there and has been since Sept.23 2002 when it
> >>> was
> >>> added.
> >> I've added a Note to 'fopen' so maybe others won't completely miss
> >> this feature and look as foolish as I do right now. :-)
> >
> > If it's anything like the helpful note I added about using copy( source,
> > dest ) where dest accidentally points to source (due to linking), you'll
> > get a nice retarded email like the following:
>
> You could volunteer to help maintain the user notes. It it thankless
> and tedious work to keep up with the flood of user notes being
> submitted.

I'll keep that in mind for the future when I have more free time (2 kids
under 3 is good for keeping me occupied beyond work atm :).

> A huge percentage of them being either spam, product pitches
> or really dumb questions. The fact that occasionally a useful note gets
> deleted by mistake doesn't surprise me.

Point taken, just sort of feels like slap in the face after you go to
the effort to write a useful note :)

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

attached mail follows:


Robert Cummings wrote:
> On Mon, 2006-04-10 at 23:24, Rasmus Lerdorf wrote:
>> Robert Cummings wrote:
>>> On Mon, 2006-04-10 at 23:11, Richard Lynch wrote:
>>>> On Mon, April 10, 2006 9:59 pm, Rasmus Lerdorf wrote:
>>>>> Richard Lynch wrote:
>>>>>> It would be REALLY NIFTY if fopen and friends which understand all
>>>>>> those protocols of HTTP FTP HTTPS and so on, allowed one to set a
>>>>>> timeout for URLs, but they don't and nobody with the skills to
>>>>>> change
>>>>>> that (not me) seems even mildly interes