I am a php beginner, so apologize if this question is silly.
I am encountering apparently random script stops when I try to
get a remote HTML file with either file() or fopen(). A
typical code snippet:
echo 'here we go...';
$handle=fopen($url,'r');
echo 'and here we are';
if ($handle==FALSE)
{
do some stuff
}
I can try to use that to obtain several hundred similar files,
and have it go through a dozen or a hundred of them getting,
every time,
here we go...and here we are
and, more important, the file read just fine. But, sooner
or later in such a run, I will get the first echoed message but
not the second (that is, "here we go..." and nothing else) and
the script will have stopped dead. I have this in the script:
function bye()
{
echo 'SHUT DOWN!'.$p;
}
register_shutdown_function('bye');
I never see that message when it stops (though i do if the
script hits an exit statement). I also have this:
set_time_limit(0);
The php version is 4.2.2 on a server running BSD.
I encounter exactly the same behavior trying to fetch files
using
$remotefile=file($url);
On random occasions it just never comes out of the function.
This is driving me mad. Can anyone tell me what I am doing
wrong?
--
Cordially,
Eric Walker
Owlcroft House 6 1975
On 02 Sep 2003 10:27:37 GMT, Peter Jones wrote: "Eric Walker" <ew*****@owlcroft.com> wrote in news:rj********************************@news.indi vidual.net:
I am a php beginner, so apologize if this question is silly.
I am encountering apparently random script stops when I try to get a remote HTML file with either file() or fopen(). A typical code snippet:
echo 'here we go...'; $handle=fopen($url,'r'); echo 'and here we are'; if ($handle==FALSE) { do some stuff } else fclose($handle);
I would imagine you are hitting the system limit on concurrently open files, if there isn't an fclose() somewhere closing them again... Adding the above line ought to fix that.
Sorry, no, it isn't that. For simplicity's sake, I just showed
the immediately relevant lines in the snippet; there is indeed
a line--
if ($handle!==FALSE) fclose $handle;
farther on.
PS: Is that logic correct? 'do some stuff' if file did NOT open?
Some error-recording stuff, yes, and re-try logic; there is
also continuing script that proceeds if the handle is valid
(and which eventually gets to that file-close). But the script
never gets to use anything in that block because it never
emerges from the file-open (or, with file(), file-get) function
call.
What especially puzzles me is that the script apparently
doesn't even activate the registered shutdown function when it
quits: it just . . . stops.
--
Cordially,
Eric Walker
My opinions on English are available at http://owlcroft.com/english/
Eric Walker wrote: On 02 Sep 2003 10:27:37 GMT, Peter Jones wrote:"Eric Walker" <ew*****@owlcroft.com> wrote in news:rj********************************@news.ind ividual.net:
I am a php beginner, so apologize if this question is silly.
I am encountering apparently random script stops when I try to get a remote HTML file with either file() or fopen(). A typical code snippet:
echo 'here we go...'; $handle=fopen($url,'r'); echo 'and here we are'; if ($handle==FALSE) { do some stuff } else fclose($handle);
I would imagine you are hitting the system limit on concurrently open files, if there isn't an fclose() somewhere closing them again... Adding the above line ought to fix that.
Sorry, no, it isn't that. For simplicity's sake, I just showed the immediately relevant lines in the snippet; there is indeed a line--
if ($handle!==FALSE) fclose $handle;
farther on.
Dummy question: see the allow_url_fopen in php.ini whether it is
enabled. If not, then enable it... PS: Is that logic correct? 'do some stuff' if file did NOT open?
Some error-recording stuff, yes, and re-try logic; there is also continuing script that proceeds if the handle is valid (and which eventually gets to that file-close). But the script never gets to use anything in that block because it never emerges from the file-open (or, with file(), file-get) function call.
What especially puzzles me is that the script apparently doesn't even activate the registered shutdown function when it quits: it just . . . stops.
if ($handle!==FALSE) fclose $handle;
or:
if ($handle!=FALSE) fclose $handle;
IroNiQ
--
Web: http://ironiq.hu/
Email: ir**@ironiq.hu
"Peter Jones" <jo*****@optushome.com.au> wrote in message
news:Xn*****************************@210.49.20.254 ... "Eric Walker" <ew*****@owlcroft.com> wrote in news:rj********************************@news.indiv idual.net:
On 02 Sep 2003 10:27:37 GMT, Peter Jones wrote:
[snip]
Sorry, no, it isn't that. For simplicity's sake, I just showed the immediately relevant lines in the snippet; there is indeed a line--
if ($handle!==FALSE) fclose $handle;
farther on.
[snip]
(Also, as Krisztian pointed out, it should probably be "!=" rather than "!==", although simple testing on my part seems to suggest "!==" is working the same way as "!=". According to the precedence rules it should be parsing as "((!)==)" -- but actual usage of such a construct may well be undefined and therefore not do what you think it will...)
No, !== is quite different to !=, as is === to ==
Look at Comparison operators in PHP manual
$x = 0;
$y = false;
if ( $x === false ) { // this is not true, x is not FALSE, its 0 }
if ( $y === false ) { // this is true }
if ( !$x ) { // this is true, 0 is classed as a logical false, but it does
not have the _type_ false, it is type integer }
Similary for !== ....
if ( $x !== false ) { // true, it is type interger, no false, despite the
fact that.... if ( !$x ) would be true
if ( $y !== false ) { // false, y does have type false ... }
I mut say here I do tend to test for :
if ( $handle ) { fclose($handle); }
myself, it reads easier, but i guess...
if ( $handle !== false ) { ... }
is more strictly correct, becuase fopen returns false on failure, so
if ( $handle === false ) { it failed... }
conversly
if ( $handle !== false ) { it worked }
This means should file handles suddenly start allowing 0 as a file handle it
would still work.
Thanks
Mark
---------------------------------------------------------------------------
Windows, Linux and Internet Development Consultant
Email: co*******@scriptsmiths.com
Web: http://www.scriptsmiths.com
---------------------------------------------------------------------------
[snip] HTH, Pete.
On 03 Sep 2003 13:27:06 GMT, Peter Jones wrote: "Eric Walker" <ew*****@owlcroft.com> wrote in news:rj********************************@news.indi vidual.net:
On 02 Sep 2003 10:27:37 GMT, Peter Jones wrote:
I would imagine you are hitting the system limit on concurrently open files, if there isn't an fclose() somewhere closing them again...
Sorry, no, it isn't that. For simplicity's sake, I just showed the immediately relevant lines in the snippet; there is indeed a line--
if ($handle!==FALSE) fclose $handle;
farther on.
Are you sure that the script is actually reaching (and correctly processing) the fclose()? Also, are you sure you are not reassigning the value of $handle somewhere before you do the fclose($handle) -- something I've been caught by a time or two in the past...
I am sure. Moreover, the problem originally arose using
file(), which does not involve an explicit open/close process
using a handle; I only went back to fopen/fclose to see if that
would work any better (it didn't).
[...] What especially puzzles me is that the script apparently doesn't even activate the registered shutdown function when it quits: it just . . . stops.
The only other thing I can think to suggest is to specifically check which file it is stopping on. Is it the same file each time? If so, is there something else accessing that file at the same time?
No, not the same file each time: the "problem" file will be one
that, on the next run, will be picked up just fine (and
probably was on an earlier run)--it doesn't seem to be
associated with the file being sought (though it may reflect
something dicey in the server's behavior or returned headers--I
haven't tried to look at those). Incidentally, the problem
arise both with files off remote servers (such as Amazon and
ESPN) and with php scripts of mine on my ISP's own server.
Maddening!
--
Cordially,
Eric Walker
My opinions on English are available at http://owlcroft.com/english/
"Mark Hewitt" <co*******@scriptsmiths.com> wrote in
news:3f**************@hades.is.co.za: No, !== is quite different to !=, as is === to == Look at Comparison operators in PHP manual
Thanks, Mark, for elaborating on that. I did actually look in my near-to-
hand reference for "!==" before I allowed myself to post under the premise
that it was invalid. My reference ('PHP and MySQL Web Development') mentions
"===" but not "!==". I guess I've learned two things -- one being that I
can't necessarily totally trust this book now... :-)
I guess "!==" is to "===" as "!=" is to "=="?!
Apologies all round for taking the discussion down a false trail.
Pete.
In article <Xn*****************************@210.49.20.254>,
Peter Jones <jo*****@optushome.com.au> wrote: I guess "!==" is to "===" as "!=" is to "=="?!
Correct. The former set evaluates value and type, while the latter set
evaluates only value. So, for instance:
1==TRUE //because their values evaluate as equivalent
-but-
1!==TRUE //because a boolean is not an integer
--
CC This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Lowell Kirsh |
last post by:
I have a script which I use to find all duplicates of files within a
given directory and all its subdirectories. It seems like it's longer
than it needs to be but I can't figure out how to shorten...
|
by: bayouprophet |
last post by:
Cant get menu script to to put linked page in the same frame. I am
new to Java
and I am wondering what am I doing wrong? below are my java applet
file, frame.html file, and my text file and one...
|
by: Sergey |
last post by:
Hi everyone,
It looks like a mystery, but I hope there should be some explanation to
the issue I experience. Once in a blue moon a random stored procedure
stops working the way it was designed....
|
by: Jason |
last post by:
I am attempting to have an asp page call a batch file.
I had it working, I was high on life and then I decided to log off the
server. Once I did, the code would no longer work. When I logged back...
|
by: Martin Jørgensen |
last post by:
Hi,
In continuation of the thread I made "perhaps a stack problem? Long
calculations - strange error?", I think I now got a "stable" error,
meaning that the error always seem to come here now...
|
by: Terry Olsen |
last post by:
I have a windows service that has been running fine for almost 6 months.
Last week, it just stopped working. It is still in the task list and
still shows "started" in the service manager. There...
|
by: rsteph |
last post by:
I have a script that shows the time and date. It's been working on my site for quite a while now. Suddenly it stops showing up, after getting my drop down menu to work.
If I put text between the...
|
by: GazK |
last post by:
I have been using an xml parsing script to parse a number of rss feeds
and return relevant results to a database. The script has worked well
for a couple of years, despite having very crude...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Many websites have a form or a link you can use to download a file. You click a form button or click...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |