![]() |
Simple script fails with php5
I have a script that reads the file contents of a site. My host recently upgraded to php 5 and the script doesn't work correctly. It still runs without errors but takes much longer and no results are found. I've narrowed down the code to this
Code:
$file = @fopen($filename, "r"); |
If you replaced that code with the code below, is it any faster?
php Code:
|
Since you say that the problem appears to lie with the
feof line (the @ before fopen won't be helping at all) it appears to be a timeout problem. See the warning notes on the feof manual page. The second one may be the exact problem that you're facing (suppressed fopen error, infinite feof loop until timeout).For a start, remove the @ before fopen and see what error is being generated as I suspect there will be one. |
Thanks for the replies. I tried both of the suggestions but got different results from before. I must not have commented out the next line in the code since that is where it is failing - on an eregi call. What I did was add some code to record the results of that call. In php 4, the results range from FALSE to some number. In php 5, they are always FALSE. The reason for the delay is that since the result isn't being found, it has to cycle through all of the pages. In php 4, the result is found on the first page so it stops. So the problem is with that call. The code looks like this:
Code:
$fp = fopen("track.txt","w");Quote:
|
Code:
"<cite>(.*)</cite>" <-- Regular Expression [ The (.*) part ] |
Thanks, but I don't understand your reply. Is there something wrong with "<cite>(.*)</cite>"? It works find in php4. Does something need to be changed for it to work with php5?
The second if is empty because it doesn't affect this problem and would just clutter the example. |
I don't think anything is wrong, its just that PHP 5.3 will not accept that regular expression/code block.
Code:
Note: As of PHP 5.3.0 the regex extension is deprecated, calling this function will issue an E_DEPRECATED notice. |
Quote:
ereg, eregi, split and sql_regcase. Can you call eregi in a basic script and get the desired results? For example, does the following script simply echo 3?PHP Code:
$var contain the same value(s) when ran on both PHP versions? |
I tried
PHP Code:
Here's the code used for both of the above: PHP Code:
|
Can no one see the reason for the failure in this code?
|
I know this probably won't help you much, but the script seems to run fine on my PHP5 installation.
Try replacing the eregi with preg_match, of course you would have to change your expression somewhat: PHP Code:
|
Thanks to all those who helped. I was finally able to determine that fopen was causing the problem, although I don't know why. I did a search on google and see others are having the same problem but no fix was mentioned. I ended up replacing fopen with a curl read and it is woking now.
|
| All times are GMT. The time now is 03:25 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0