Jump to content


Photo

Php Script ends unexpectedly?


  • Please log in to reply
7 replies to this topic

#1 ksteuber

ksteuber
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationCalifornia, USA

Posted 21 October 2006 - 09:03 PM

Ok, somebody must have asked this question before, but I can't find it.

I'm using PHP 4.3.11, and I'm in the middle of writing a page that retreives other pages and displays them.

The problem I'm having is that after it gets the page and makes some changes to it, the script is supposed to display the whole page, then save a copy of it to the server as shown in the excerpt of code below:
echo $done; //$done is the variable that has site stored to it.
$fp = fopen("/home/content/k/s/t/ksteuber/html/php_uploads/logs/".$URL." - ".date("F j, Y, g:i a"),"w");
fwrite($fp,$done);
fclose($fp);

Very, very straight forward. However, it only shows about half of the page, and doesn't write any file, so I can only assume that the script just stops halfway through the command. I thought it might be a time issue, but the page takes 1.320 sec to load from when I send the request for the page to when I recieve it, and the script claims that it has spent 0.450 sec up to the point that it sends the file (I believe scripts have a 30 sec timeout, not .5 sec)

Does anybody know why the script would just stop?

Note: The result of the script can be found by going to http://www.kirksteuber.com/ and clicking on "In page proxy"
The full text of the code can be found at http://www.kirksteuber.com/parser.txt

#2 ksteuber

ksteuber
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationCalifornia, USA

Posted 28 October 2006 - 07:11 PM

Does anybody know?
Shouldn't there be an easy solution?

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 28 October 2006 - 07:41 PM

Are you sure the fopen() works. It will return 'false' if it fails.

Have you checked the content of the file you are reading into the $done variable immediately after the point at which it stops. eg is there a < with no closing > so nothing is displayed?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 ksteuber

ksteuber
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationCalifornia, USA

Posted 29 October 2006 - 01:28 AM

as for fopen, I have no way of knowing if it works, since the script doesn't even get past the echo command (it desplays a portion of $done, and not the rest of it, and I have tried but I can't get any other funtions that I use after "echo $done;" to give me a sign that it has been executed at all)

as for the second idea, I have been looking at the source after I run the script, so I would see any abnormally long tags.

#5 pendelton

pendelton
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationUK

Posted 29 October 2006 - 01:32 AM

Does the file already exist and is the file/folder on the server writeable? Also, try setting $done to a simple string like "hello" until you get things working.

#6 ksteuber

ksteuber
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationCalifornia, USA

Posted 29 October 2006 - 04:22 AM

Ok, so I tried the $done="hello"; idea, which made it so that the script would return a fopen error which turned out to be because $URL contained "http://" and "/" is a forbidden character in linux filenames. (Oops, thats an embarassing mistake)

I changed the code to:
echo $done;
$filename = "/home/content/k/s/t/ksteuber/html/php_uploads/logs/".substr($URL,7)." - ".date("F j, Y, g:i a");
$fp = fopen($filename,"w");
fwrite($fp,$done);
fclose($fp);

Now it makes the file properly, and the file contains the entire site (Yay). However, "echo $done;" still is not working properly. When I view the webpage, I still get only a fraction of $done.

I also tried to export some different text at that point in the script that was the same length as $done would have been, but that didn't work either.

But wait, here's the weird part. If I make a completely different script that echos that much info, but doesn't execute any of the other commands in the original script, it works. So presumably there is something else in the script that is interfering with the echo command.
(The full code of the script is still at: http://www.kirksteuber.com/parser.txt)

#7 pendelton

pendelton
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationUK

Posted 29 October 2006 - 09:23 AM

Are you saying that you echo doesn't work when you output the content of a file? If so, don't forget that you are viewing it via HTML which will format the output (or at least probably get confused by some of your file format). Get your echo to echo's the file content that doesn't quite work then do view source on the page. You should find that it is all there in the source but isn't all displayed as you expect in the broweser.

#8 ksteuber

ksteuber
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationCalifornia, USA

Posted 30 October 2006 - 03:06 AM

ksteuber:

...I have been looking at the source after I run the script...








0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users