php-general Digest 4 Feb 2010 12:21:57 -0000 Issue 6573

Topics (messages 301794 through 301813):

Re: Thinking of moving to .NET because of standalone... any suggestions?
        301794 by: Robert Cummings
        301795 by: Ashley Sheridan
        301797 by: Robert Cummings
        301798 by: David Murphy
        301800 by: Bastien Koert
        301803 by: Ryan S

Can't get my PHP-generated RSS to serve properly
        301796 by: Brian Dunning
        301799 by: Robert Cummings
        301801 by: Brian Dunning
        301802 by: Michael A. Peters

PHP Manual problems
        301804 by: clancy_1.cybec.com.au
        301805 by: Ashley Sheridan
        301809 by: Jochem Maas

stream_select() not working on regular files?
        301806 by: Dennis J.
        301807 by: Ashley Sheridan
        301808 by: Dennis J.
        301812 by: Eric Lee
        301813 by: Dennis J.

PHP User
        301810 by: abby ragz
        301811 by: Paul M Foster

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


Ryan S wrote:
Thanks for the reply Michael, Robert and Jochem,

makes sense, a native windows app is going to look more in place than any of 
the demos and graphics i have seen of GTK.

Was also looking at GTK-Builder, unfortunately you really have to hunt for each 
scrap of new info - which is why I'm guessing open source falls back a bit 
compared to M$'s offerings.

MS shoehorning something into dotnet sounds interesting, will ask my pal google 
what he can bring up ;)
I did read about FLEX but i have pretty much complete php scripts that i want 
to use in a desktop environment, FLEX wouldnt do for my (present) needs.

Will look up WxWidgets and HipHop (somehow i get the feeling i'm gonna be 
drowned in millions of results that have rap lyrics instead of programming 
information - should be a test of my patience :-))    )

Anyone have anything more to add/advise, please do so.

Don't look at WxWidgets, I was wrong about that... it's WinBinder you want to look at. You shouldbe pretty good looking up HipHop if you include PHP in the keywords list :)

In fact "php hiphop" hits the right stride in the top entries (I just did a check :) Heck, hiphop alone gets you some of the info on the PHP version in the first page of results.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
On Wed, 2010-02-03 at 14:02 -0500, Robert Cummings wrote:

> 
> Ryan S wrote:
> > Thanks for the reply Michael, Robert and Jochem,
> > 
> > makes sense, a native windows app is going to look more in place than any 
> > of the demos and graphics i have seen of GTK.
> > 
> > Was also looking at GTK-Builder, unfortunately you really have to hunt for 
> > each scrap of new info - which is why I'm guessing open source falls back a 
> > bit compared to M$'s offerings.
> > 
> > MS shoehorning something into dotnet sounds interesting, will ask my pal 
> > google what he can bring up ;)
> > I did read about FLEX but i have pretty much complete php scripts that i 
> > want to use in a desktop environment, FLEX wouldnt do for my (present) 
> > needs.
> > 
> > Will look up WxWidgets and HipHop (somehow i get the feeling i'm gonna be 
> > drowned in millions of results that have rap lyrics instead of programming 
> > information - should be a test of my patience :-))    )
> > 
> > Anyone have anything more to add/advise, please do so.
> 
> Don't look at WxWidgets, I was wrong about that... it's WinBinder you 
> want to look at. You shouldbe pretty good looking up HipHop if you 
> include PHP in the keywords list :)
> 
> In fact "php hiphop" hits the right stride in the top entries (I just 
> did a check :) Heck, hiphop alone gets you some of the info on the PHP 
> version in the first page of results.
> 
> Cheers,
> Rob.
> -- 
> http://www.interjinn.com
> Application and Templating Framework for PHP
> 


Personally, I'd go with a more suitable language for desktop application
development. PHP, to me, is great for two things: websites and command
line scripts. If I wanted to develop for the desktop market, I'd go with
either C++ and compile for each environment as needed, or go with .Net
or Java to make it more portable. It might make more sense to convert
some of your existing PHP code into a different language.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote:
On Wed, 2010-02-03 at 14:02 -0500, Robert Cummings wrote:

Ryan S wrote:
Thanks for the reply Michael, Robert and Jochem,

makes sense, a native windows app is going to look more in place than any of 
the demos and graphics i have seen of GTK.

Was also looking at GTK-Builder, unfortunately you really have to hunt for each 
scrap of new info - which is why I'm guessing open source falls back a bit 
compared to M$'s offerings.

MS shoehorning something into dotnet sounds interesting, will ask my pal google 
what he can bring up ;)
I did read about FLEX but i have pretty much complete php scripts that i want 
to use in a desktop environment, FLEX wouldnt do for my (present) needs.

Will look up WxWidgets and HipHop (somehow i get the feeling i'm gonna be 
drowned in millions of results that have rap lyrics instead of programming 
information - should be a test of my patience :-))    )

Anyone have anything more to add/advise, please do so.
Don't look at WxWidgets, I was wrong about that... it's WinBinder you want to look at. You shouldbe pretty good looking up HipHop if you include PHP in the keywords list :)

In fact "php hiphop" hits the right stride in the top entries (I just did a check :) Heck, hiphop alone gets you some of the info on the PHP version in the first page of results.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP



Personally, I'd go with a more suitable language for desktop application
development. PHP, to me, is great for two things: websites and command
line scripts. If I wanted to develop for the desktop market, I'd go with
either C++ and compile for each environment as needed, or go with .Net
or Java to make it more portable. It might make more sense to convert
some of your existing PHP code into a different language.

In many cases I'd agree with you, but the OP indicated they have existing code/libraries that they want to leverage. In this case, I'm not so certain creating a second redundant library in the desktop oriented language of choice, such that you now have two codebases to maintain, is a compelling argument in favour of such a move.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
Ryan, 

You may want to consider:

NuSphere PhpDock - unique PHP deployment solution

PhpDock is a deployment platform for PHP applications.
PhpDock enables you to deploy PHP web application as a Stand Alone Windows
Desktop application w/o any changes in the code.
PhpDock combines NuSphere's powerful embeded Srv webserver and the browser
components.

With PhpDock, your php applications will work right out of the box. There's
no need to provide long and complicated instructions on Apache and Php
installation to your clients. PhpDock site license lets you distribute this
deployment solution along with your php applications to provide easy and
comprehensive installation and instant functioning of your php scripts.


http://www.nusphere.com/products/phpdock.htm

Hope this helps
David Murphy


-----Original Message-----
From: Ryan S [mailto:[email protected]] 
Sent: Wednesday, February 03, 2010 11:10 AM
To: php php
Subject: [PHP] Thinking of moving to .NET because of standalone... any
suggestions?

Hey Guys,

Coming from a C and Java background I just loved PHP and have been
programming with it for years thanks in a large part to the kind people on
this list... present and past (Immediately the name John Holmes comes to
mind.. i hope the dude is well)
but now I have have to leave PHP or split time between php and .NET for just
one reason:

.NET offers a way to run programs using the Windows GUI / stand alone
executable

There always was talk on the list about running php code as standalone, but
since I had a long absence from the list sorry if I missed any new
updates... but I'm hoping someone can offer a way to run php standalone
executable.

Before posting I always google, and the main results I have gotten so far
is:
priado blender
and PHP-GTK

but no way to kind of drag and drop what you need like visual studio (i dont
know how to use it yet, but been reading) or some other visual development
tool like visual basic.

I need to make a few standalones programs that will run (mostly) on
Windows... is there any other way that I have not found that i can use PHP
instead of learning something new like .NET?

I have resisted going "the microsoft way" for years.. looks like my luck has
run out...

Thanks,
Ryan



      

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


--- End Message ---
--- Begin Message ---
On Wed, Feb 3, 2010 at 2:37 PM, Robert Cummings <[email protected]> wrote:
> Ashley Sheridan wrote:
>>
>> On Wed, 2010-02-03 at 14:02 -0500, Robert Cummings wrote:
>>
>>> Ryan S wrote:
>>>>
>>>> Thanks for the reply Michael, Robert and Jochem,
>>>>
>>>> makes sense, a native windows app is going to look more in place than
>>>> any of the demos and graphics i have seen of GTK.
>>>>
>>>> Was also looking at GTK-Builder, unfortunately you really have to hunt
>>>> for each scrap of new info - which is why I'm guessing open source falls
>>>> back a bit compared to M$'s offerings.
>>>>
>>>> MS shoehorning something into dotnet sounds interesting, will ask my pal
>>>> google what he can bring up ;)
>>>> I did read about FLEX but i have pretty much complete php scripts that i
>>>> want to use in a desktop environment, FLEX wouldnt do for my (present)
>>>> needs.
>>>>
>>>> Will look up WxWidgets and HipHop (somehow i get the feeling i'm gonna
>>>> be drowned in millions of results that have rap lyrics instead of
>>>> programming information - should be a test of my patience :-))    )
>>>>
>>>> Anyone have anything more to add/advise, please do so.
>>>
>>> Don't look at WxWidgets, I was wrong about that... it's WinBinder you
>>> want to look at. You shouldbe pretty good looking up HipHop if you include
>>> PHP in the keywords list :)
>>>
>>> In fact "php hiphop" hits the right stride in the top entries (I just did
>>> a check :) Heck, hiphop alone gets you some of the info on the PHP version
>>> in the first page of results.
>>>
>>> Cheers,
>>> Rob.
>>> --
>>> http://www.interjinn.com
>>> Application and Templating Framework for PHP
>>>
>>
>>
>> Personally, I'd go with a more suitable language for desktop application
>> development. PHP, to me, is great for two things: websites and command
>> line scripts. If I wanted to develop for the desktop market, I'd go with
>> either C++ and compile for each environment as needed, or go with .Net
>> or Java to make it more portable. It might make more sense to convert
>> some of your existing PHP code into a different language.
>
> In many cases I'd agree with you, but the OP indicated they have existing
> code/libraries that they want to leverage. In this case, I'm not so certain
> creating a second redundant library in the desktop oriented language of
> choice, such that you now have two codebases to maintain, is a compelling
> argument in favour of such a move.
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

check out http://www.php-compiler.net/doku.php

-- 

Bastien

Cat, the other other white meat

--- End Message ---
--- Begin Message ---
Thanks for the links and advise guys!

Of all I found this most interesting as it would run native:


>check out http://www.php-compiler.net/doku.php

unfortunately I think this project is dead or at best stagnant because the 
server is slower than a 99 year old on weed and forums link dead. Documentation 
is badly limited as well.

 But if someone was used this or is using this, would love to hear from you.

Till then am back to checking out the other recommendations and googling.
Keep any other advise/links coming ;) they are most appreciated.

Cheers!
R



      

--- End Message ---
--- Begin Message ---
Hey all -

Glad some of you found that sample data helpful.   :-)

I use PHP/MySQL to generate RSS feeds of my podcasts. The feed is submitted as 
*.xml and I use .htaccess to redirect it to my PHP document. The start of the 
document sets the right header and outputs the <? & ?> to prevent PHP from 
trying to process the leading XML line as code (this is cleaned up a bit for 
readability):

<?php
header("content-type: application/rss+xml");
echo '<?';
?>
xml version="1.0" encoding="UTF-8"
<?php
echo '?>';
?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"; 
xmlns:atom="http://www.w3.org/2005/Atom"; version="2.0">

This has always worked fine on one podcast, but on a new one it's not. You can 
see the results here:
http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Finfactvideo.com%2Fpodcast.php

It's throwing a 500 error, a parsing error, and complaining that feeds should 
not be served with the "text/html" type, even though I'm serving the right 
header. Other PHP pages on this site work fine, and there are no special Apache 
directives on my site that works that are missing here. Can anyone suggest what 
I might be missing?

- Brian

--- End Message ---
--- Begin Message ---
Brian Dunning wrote:
Hey all -

Glad some of you found that sample data helpful.   :-)

I use PHP/MySQL to generate RSS feeds of my podcasts. The feed is submitted as *.xml and 
I use .htaccess to redirect it to my PHP document. The start of the document sets the 
right header and outputs the <? & ?> to prevent PHP from trying to process the 
leading XML line as code (this is cleaned up a bit for readability):

<?php
header("content-type: application/rss+xml");
echo '<?';
?>
xml version="1.0" encoding="UTF-8"
<?php
echo '?>';
?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"; 
xmlns:atom="http://www.w3.org/2005/Atom"; version="2.0">

This has always worked fine on one podcast, but on a new one it's not. You can 
see the results here:
http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Finfactvideo.com%2Fpodcast.php

It's throwing a 500 error, a parsing error, and complaining that feeds should not be 
served with the "text/html" type, even though I'm serving the right header. 
Other PHP pages on this site work fine, and there are no special Apache directives on my 
site that works that are missing here. Can anyone suggest what I might be missing?

A 500 error is indicating a failure at the server/script level. The parse error I assume you see in your error logs. Correct the parse error and you should be able to move forward. The text/html error is related to the parse error since that prevents your script from running and properly setting the content type header.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
Ugh. Stupid me. Thanks Robert. It was a type elsewhere in my code further down 
the page. I was so hung up thinking it was an encoding or MIME or delivery 
problem I didn't think to check my PHP.

Someone slap me upside the head please.


--- End Message ---
--- Begin Message ---
Brian Dunning wrote:
Hey all -

Glad some of you found that sample data helpful.   :-)

I use PHP/MySQL to generate RSS feeds of my podcasts. The feed is
submitted as *.xml and I use .htaccess to redirect it to my PHP
document. The start of the document sets the right header and outputs
the <? & ?> to prevent PHP from trying to process the leading XML
line as code (this is cleaned up a bit for readability):

<?php header("content-type: application/rss+xml"); echo '<?'; ?> xml
version="1.0" encoding="UTF-8" <?php echo '?>'; ?> <rss
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd";
xmlns:atom="http://www.w3.org/2005/Atom"; version="2.0">

This has always worked fine on one podcast, but on a new one it's
not. You can see the results here: http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Finfactvideo.com%2Fpodcast.php


It's throwing a 500 error, a parsing error, and complaining that
feeds should not be served with the "text/html" type, even though I'm
serving the right header. Other PHP pages on this site work fine, and
there are no special Apache directives on my site that works that are
missing here. Can anyone suggest what I might be missing?

- Brian

Don't know if it is beneficial to you, but this is what I use (and wrote) for RSS feeds -

http://www.phpclasses.org/browse/package/5942.html

Not tried it for podcasts.

--- End Message ---
--- Begin Message ---
Recently I have frequently found, especially in the morning (GMT 2200 - 0200), 
that I can
open a bookmark in the manual, for example 
http://www.php.net/manual/en/ref.image.php.
But if I then do a search of any type I get 'The page cannot be displayed'.  I 
then cannot
reach any page, including the one I originally opened.

This morning, after some fiddling, I found that if I closed the browser, and 
re-opened it
I could then see the original bookmark again, and link to some pages, but 
others would
again crash the browser, as would all searches.

I am using IE6, and have seen a message that I should update my browser, but 
only when the
page is displaying properly.  Firefox 3.5.5 immediately converted the above to
http://au2.php.net/manual/en/ref.image.php. and then told me "The manual page 
you are
looking for (http://au2.php.net/manual/en/ref.image.php.) is not available on 
this server
right now."

Is this due to maintenance, or somesuch, or is it something in my system?


--- End Message ---
--- Begin Message ---
On Thu, 2010-02-04 at 11:32 +1100, [email protected] wrote:

> Recently I have frequently found, especially in the morning (GMT 2200 - 
> 0200), that I can
> open a bookmark in the manual, for example 
> http://www.php.net/manual/en/ref.image.php.
> But if I then do a search of any type I get 'The page cannot be displayed'.  
> I then cannot
> reach any page, including the one I originally opened.
> 
> This morning, after some fiddling, I found that if I closed the browser, and 
> re-opened it
> I could then see the original bookmark again, and link to some pages, but 
> others would
> again crash the browser, as would all searches.
> 
> I am using IE6, and have seen a message that I should update my browser, but 
> only when the
> page is displaying properly.  Firefox 3.5.5 immediately converted the above to
> http://au2.php.net/manual/en/ref.image.php. and then told me "The manual page 
> you are
> looking for (http://au2.php.net/manual/en/ref.image.php.) is not available on 
> this server
> right now."
> 
> Is this due to maintenance, or somesuch, or is it something in my system?
> 
> 


The bookmarked page you are seeing is probably the offline cached
version from your browser. Try visiting that bookmark from another
browser.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Op 2/4/10 1:32 AM, [email protected] schreef:
> Recently I have frequently found, especially in the morning (GMT 2200 - 
> 0200), that I can
> open a bookmark in the manual, for example 
> http://www.php.net/manual/en/ref.image.php.
> But if I then do a search of any type I get 'The page cannot be displayed'.  
> I then cannot
> reach any page, including the one I originally opened.
> 
> This morning, after some fiddling, I found that if I closed the browser, and 
> re-opened it
> I could then see the original bookmark again, and link to some pages, but 
> others would
> again crash the browser, as would all searches.
> 
> I am using IE6, and have seen a message that I should update my browser, but 
> only when the
> page is displaying properly.  Firefox 3.5.5 immediately converted the above to
> http://au2.php.net/manual/en/ref.image.php. and then told me "The manual page 
> you are
> looking for (http://au2.php.net/manual/en/ref.image.php.) is not available on 
> this server
> right now."

there are stacks of mirrors. try one of:

au.php.net
tw.php.net
tw2.php.net
tn.php.net
tn2.php.net
sg.php.net
sg2.php.net

... guessing those are closest to you.

as for using IE6 ... WTF ... you do realise this is essentially a web 
developers mailing list right?


> 
> Is this due to maintenance, or somesuch, or is it something in my system?
> 
> 


--- End Message ---
--- Begin Message ---
Hi,
I'm trying to implement something similar to "tail -f" in php but I'm running into a problem. The issue occurs when I've reached the end of the file. From here I basically have to loop until new lines get appended to the file but I would like to respond immediately when then happens. There are three options that I can see:

1. Busy-loop
pro: I can process new lines immediately
contra: Excessivley CPU intensive => not a real option

2. add a sleep(1) to the loop
pro: No longer kills the CPU
contra: I might get a 1 second delay until I can process new lines

3. stream_select(array($fh),null,null,1)
pro: sleeps for one second but returns earlier if new data arrives
contra: doesn't seem to work in files?

Method 3 is the preferable one but doesn't seem to work:

$fh = fopen("testfile","r");
$r = array($fh);
while( ($n = stream_select($r,$w=null,$e=null,1)) == 1 ) {
    echo fgets($fh);
}

This program will loop forever because stream_select() will always return 1 even at the end of the file.

Is there any other way to accomplish this?

Regards,
  Dennis

--- End Message ---
--- Begin Message ---
On Thu, 2010-02-04 at 01:41 +0100, Dennis J. wrote:

> Hi,
> I'm trying to implement something similar to "tail -f" in php but I'm 
> running into a problem.
> The issue occurs when I've reached the end of the file. From here I 
> basically have to loop until new lines get appended to the file but I would 
> like to respond immediately when then happens. There are three options that 
> I can see:
> 
> 1. Busy-loop
> pro: I can process new lines immediately
> contra: Excessivley CPU intensive => not a real option
> 
> 2. add a sleep(1) to the loop
> pro: No longer kills the CPU
> contra: I might get a 1 second delay until I can process new lines
> 
> 3. stream_select(array($fh),null,null,1)
> pro: sleeps for one second but returns earlier if new data arrives
> contra: doesn't seem to work in files?
> 
> Method 3 is the preferable one but doesn't seem to work:
> 
> $fh = fopen("testfile","r");
> $r = array($fh);
> while( ($n = stream_select($r,$w=null,$e=null,1)) == 1 ) {
>      echo fgets($fh);
> }
> 
> This program will loop forever because stream_select() will always return 1 
> even at the end of the file.
> 
> Is there any other way to accomplish this?
> 
> Regards,
>    Dennis
> 


I thought that once it reached the end of the file, it will return a 0
indicating no new activity?

Although, surely you want the loop to continue forever, so that new
entries added to the end of the file are shown as soon as they appear.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On 02/04/2010 02:03 AM, Ashley Sheridan wrote:
On Thu, 2010-02-04 at 01:41 +0100, Dennis J. wrote:
Hi,
I'm trying to implement something similar to"tail -f"  in php but I'm
running into a problem.
The issue occurs when I've reached the end of the file. From here I
basically have to loop until new lines get appended to the file but I would
like to respond immediately when then happens. There are three options that
I can see:

1. Busy-loop
pro: I can process new lines immediately
contra: Excessivley CPU intensive =>  not a real option

2. add a sleep(1) to the loop
pro: No longer kills the CPU
contra: I might get a 1 second delay until I can process new lines

3. stream_select(array($fh),null,null,1)
pro: sleeps for one second but returns earlier if new data arrives
contra: doesn't seem to work in files?

Method 3 is the preferable one but doesn't seem to work:

$fh = fopen("testfile","r");
$r = array($fh);
while( ($n = stream_select($r,$w=null,$e=null,1)) == 1 ) {
      echo fgets($fh);
}

This program will loop forever because stream_select() will always return 1
even at the end of the file.

Is there any other way to accomplish this?

Regards,
    Dennis


I thought that once it reached the end of the file, it will return a 0
indicating no new activity?

That's what I thought too but apparently that is not the case.

Although, surely you want the loop to continue forever, so that new
entries added to the end of the file are shown as soon as they appear.

Yes the loop is supposed to continue forever in the final version. In fact I what I'm trying to get at is a "tail -F" which means I will repeatedly reopen the file to check if it has been replaced by a new one. I just simplified the problem above to get rid of all the additional complexity and concentrate on the specific problem I have.

My expectation was that once the end of the file is reached (i.e. fgets() has consumed all lines) stream_select() should wait for 1 second (in the above example) and if nothing happens with the file in that second it should return 0. But that doesn't happen.

Regards,
  Dennis

--- End Message ---
--- Begin Message ---
On Thu, Feb 4, 2010 at 9:20 AM, Dennis J. <[email protected]> wrote:

> On 02/04/2010 02:03 AM, Ashley Sheridan wrote:
>
>> On Thu, 2010-02-04 at 01:41 +0100, Dennis J. wrote:
>>
>>> Hi,
>>> I'm trying to implement something similar to"tail -f"  in php but I'm
>>> running into a problem.
>>> The issue occurs when I've reached the end of the file. From here I
>>> basically have to loop until new lines get appended to the file but I
>>> would
>>> like to respond immediately when then happens. There are three options
>>> that
>>> I can see:
>>>
>>> 1. Busy-loop
>>> pro: I can process new lines immediately
>>> contra: Excessivley CPU intensive =>  not a real option
>>>
>>> 2. add a sleep(1) to the loop
>>> pro: No longer kills the CPU
>>> contra: I might get a 1 second delay until I can process new lines
>>>
>>> 3. stream_select(array($fh),null,null,1)
>>> pro: sleeps for one second but returns earlier if new data arrives
>>> contra: doesn't seem to work in files?
>>>
>>> Method 3 is the preferable one but doesn't seem to work:
>>>
>>> $fh = fopen("testfile","r");
>>> $r = array($fh);
>>> while( ($n = stream_select($r,$w=null,$e=null,1)) == 1 ) {
>>>      echo fgets($fh);
>>> }
>>>
>>> This program will loop forever because stream_select() will always return
>>> 1
>>> even at the end of the file.
>>>
>>> Is there any other way to accomplish this?
>>>
>>> Regards,
>>>    Dennis
>>>
>>>
>> I thought that once it reached the end of the file, it will return a 0
>> indicating no new activity?
>>
>
> That's what I thought too but apparently that is not the case.
>
>
>  Although, surely you want the loop to continue forever, so that new
>> entries added to the end of the file are shown as soon as they appear.
>>
>
> Yes the loop is supposed to continue forever in the final version. In fact
> I what I'm trying to get at is a "tail -F" which means I will repeatedly
> reopen the file to check if it has been replaced by a new one. I just
> simplified the problem above to get rid of all the additional complexity and
> concentrate on the specific problem I have.
>
> My expectation was that once the end of the file is reached (i.e. fgets()
> has consumed all lines) stream_select() should wait for 1 second (in the
> above example) and if nothing happens with the file in that second it should
> return 0. But that doesn't happen.
>
>
>
Dennis

I have just been bulit a simple test script.
It works for me with a feof call if the stream was at end of file.
But I'am not sure that is that what you want !

<?php

$fp = fopen('test.xml', 'r');
$arr = array($fp);

$w = $e = null;
while (($result = stream_select($arr, $w, $e, 1)) !== false)
{
    $line = fgets($fp);
    if (!empty($line))
    {
        echo $line;
    }
    else
    {
        if (feof($fp))
            echo 'eof',"\n";
        fclose($fp);
        $fp = null;
        break;
    }
}




Regards,
Eric,




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

--- End Message ---
--- Begin Message ---
On 02/04/2010 06:18 AM, Eric Lee wrote:
On Thu, Feb 4, 2010 at 9:20 AM, Dennis J.<[email protected]>  wrote:

On 02/04/2010 02:03 AM, Ashley Sheridan wrote:

On Thu, 2010-02-04 at 01:41 +0100, Dennis J. wrote:

Hi,
I'm trying to implement something similar to"tail -f"  in php but I'm
running into a problem.
The issue occurs when I've reached the end of the file. From here I
basically have to loop until new lines get appended to the file but I
would
like to respond immediately when then happens. There are three options
that
I can see:

1. Busy-loop
pro: I can process new lines immediately
contra: Excessivley CPU intensive =>   not a real option

2. add a sleep(1) to the loop
pro: No longer kills the CPU
contra: I might get a 1 second delay until I can process new lines

3. stream_select(array($fh),null,null,1)
pro: sleeps for one second but returns earlier if new data arrives
contra: doesn't seem to work in files?

Method 3 is the preferable one but doesn't seem to work:

$fh = fopen("testfile","r");
$r = array($fh);
while( ($n = stream_select($r,$w=null,$e=null,1)) == 1 ) {
      echo fgets($fh);
}

This program will loop forever because stream_select() will always return
1
even at the end of the file.

Is there any other way to accomplish this?

Regards,
    Dennis


I thought that once it reached the end of the file, it will return a 0
indicating no new activity?


That's what I thought too but apparently that is not the case.


  Although, surely you want the loop to continue forever, so that new
entries added to the end of the file are shown as soon as they appear.


Yes the loop is supposed to continue forever in the final version. In fact
I what I'm trying to get at is a "tail -F" which means I will repeatedly
reopen the file to check if it has been replaced by a new one. I just
simplified the problem above to get rid of all the additional complexity and
concentrate on the specific problem I have.

My expectation was that once the end of the file is reached (i.e. fgets()
has consumed all lines) stream_select() should wait for 1 second (in the
above example) and if nothing happens with the file in that second it should
return 0. But that doesn't happen.



Dennis

I have just been bulit a simple test script.
It works for me with a feof call if the stream was at end of file.
But I'am not sure that is that what you want !

<?php

$fp = fopen('test.xml', 'r');
$arr = array($fp);

$w = $e = null;
while (($result = stream_select($arr, $w, $e, 1)) !== false)
{
     $line = fgets($fp);
     if (!empty($line))
     {
         echo $line;
     }
     else
     {
         if (feof($fp))
             echo 'eof',"\n";
         fclose($fp);
         $fp = null;
         break;
     }
}

This script terminates before it hits the actual problem.
The issue is that once I've hit the EOF I need to continue the loop using the stream_select() waiting for new data.

Regards,
  Dennis

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

I used PHP 3 years back and was a standard user.

but now I want to update myself and do self - study .

 

Please advise from where should I start.

Any good site recommendations.

 

Thanks in advance:)
                                          
_________________________________________________________________
Search for properties that match your lifestyle! Start searching NOW!
http://clk.atdmt.com/NMN/go/157631292/direct/01/

--- End Message ---
--- Begin Message ---
On Thu, Feb 04, 2010 at 03:13:00PM +1030, abby ragz wrote:

> 
> Hi,
> 
> I used PHP 3 years back and was a standard user.
> 
> but now I want to update myself and do self - study .
> 
>  
> 
> Please advise from where should I start.
> 
> Any good site recommendations.

Programming PHP by Lerdorf, Tatroe, MacIntyre (O'Reilly)

http://php.net/manual/en/

For object oriented PHP code,

PHP In Action: Objects, Design, Agility by Reiersol, Baker, Shiflett
(Manning)

Paul

-- 
Paul M. Foster

--- End Message ---

Reply via email to