Web Hosting Talk







View Full Version : half working php scripts


high-flying
01-18-2004, 09:04 PM
Hi

I'm having an annoying problem here with a script that won't work properly on cpanel (works fine on my ensim servers) It gets part of the page it is supposed to but not the rest.

Script is:



PHP:
--------------------------------------------------------------------------------

$filename = "http://pcworld.idg.com.au/nindex.php?taxid=1";
$fp = fopen ("$filename", "r");
socket_set_timeout($fp, 70);
$contents = fread ($fp, 500000);
fclose($fp);
print $contents;

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



All it does is get http://pcworld.idg.com.au/nindex.php?taxid=1 and show it... has anyone one run into half-working php scripts on cpanel servers, is there something needs changing somewhere?

net-trend
01-18-2004, 09:09 PM
Error is? Most likely PEAR was not compiled with PHP resulting in errors you may see.

high-flying
01-18-2004, 09:10 PM
There isn't actually any errors not in logs nor on page... it just doesn't download the entire page.

net-trend
01-18-2004, 09:13 PM
In that case it isn't a PEAR problem, more like a scripting problem.

high-flying
01-18-2004, 09:15 PM
Originally posted by net-trend
In that case it isn't a PEAR problem, more like a scripting problem.

Works on ensim and the cpanel server this site is being moved from.... this new cpanel server is the odd one out not working... thinkign an apache problem but don't know what

choon
01-18-2004, 09:33 PM
Here are my guess and I might be wrong... is php compile with curl? Check by issuing the following command at SSH console:
php -m | grep curl
Or if you want to list all installed modules:
php -m
And the other thing is check whether is your php.ini allow_url_fopen is set to On or Off. My guess that you might be setting that to Off thus unable to open any remote url via fopen. Use this command to check your php.ini location:
php -i | grep "php.ini"
Then use:
cat /path/to/your/php.ini | grep allow_url_fopen
If you see this is set to Off... then try to set that to On and try again but there are a few exploits using this allow_url_fopen thus it is better for you to set it to Off due to security reason.

Hope these make sense though :)

blessen
01-18-2004, 09:52 PM
For the fopen to work... allow_url_fopen should be enabled.

Reference : http://in2.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen

Make sure that you have these settings
----------------
The behaviour of these functions is affected by settings in php.ini.

Table 1. Filesystem and Streams Configuration Options
Name
Default
Changeable
allow_url_fopen
"1"
PHP_INI_ALL
user_agent
NULL
PHP_INI_ALL
default_socket_timeout
"60"
PHP_INI_ALL
from
NULL
??
auto_detect_line_endings
"Off"
PHP_INI_AL
------------------------------
Reference :http://in2.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen

high-flying
01-18-2004, 09:59 PM
Curl wasn't on it, so I recompiled with it, there wasn't a allow_url_fopen line in php.ini at all, so I added it, it's still incomplete download of the page :/ (downloads a bit more that it used to though...) thanks for that help anyway.

choon
01-18-2004, 10:05 PM
Did you restart apache in the first place after recompile php and editing your php.ini?

high-flying
01-18-2004, 10:10 PM
Originally posted by choon
Did you restart apache in the first place after recompile php and editing your php.ini?

Yep

high-flying
01-18-2004, 10:15 PM
It's weird... after a few refreshes of the page I get some more of the page come through, then none..

At the moment it's cut off like:

Home
Latest
News
Features
Opinions
Interviews
Heres How
Reviews
Books

Sections
Linux
.NET
Web & You
Digital Music



JOBS
Search For Jobs
Build a Resume
HelpScreen
Categories
Home
.NET
Bugs & Fixes
Digital Music
Games
Graphics & Digital Photography
Hardware
<A



Other times it's other half compete html at the end.. script has a 70 second timeout on that, it takes less time than that to show not-complete pages.

high-flying
01-19-2004, 06:43 PM
Problem got resolved, thanks to choon for the hand via AIM :)

net-trend
01-19-2004, 08:22 PM
What was the solution, if you wouldn't mind sharing. :)

choon
01-21-2004, 11:54 PM
Here are the steps:

1. Recompile php with curl.

2. Set allow_url_fopen to On in php.ini
allow_url_fopen = On

3. Restart apache.

4. Ensure the file handler reads to end of file as the original php codes are not ensuring this EOF:

$filename = "http://pcworld.idg.com.au/nindex.php?taxid=1";
$fp = fopen ("$filename", "r");
# socket_set_timeout($fp, 70); # not necessary
if (!$fp) {
echo "Error opening $filename!";
exit;
} else {
while(! feof($fp)) {
$contents .= fread($fp, strlen($fp));
fclose($fp);
}

}
print $contents;

Hope this clear your doubts ;)

net-trend
01-22-2004, 12:50 AM
Choon,

Thanks. :) So it is an issue with the code after all eh?

choon
01-22-2004, 12:53 AM
Hi net-trend,

In the end, yes... provided php is compiled with curl and allow_url_fopen is set to On in php.ini ;)