Southperry.net
Php / MySQL update script sending empty response - Printable Version

+- Southperry.net (https://www.southperry.net)
+-- Forum: Maplers Helping Maplers (https://www.southperry.net/forumdisplay.php?fid=9)
+--- Forum: Technical Help (https://www.southperry.net/forumdisplay.php?fid=84)
+--- Thread: Php / MySQL update script sending empty response (/showthread.php?tid=38306)



Php / MySQL update script sending empty response - Toastyc12 - 2011-02-23

Hello.

I run and manage a small website for my guild / alliance, in which I have an automated rank / level retrieval script.
A couple months back, I made a quick script in PHP that takes values from a webpage, and inserts them into an SQL database. The script worked for a while, until recently when my web host upgraded to a new server. Now the script always gives me "(52) Empty reply from server" (using curl).

My knowledge on fixing these sorts of things is fairly limited, so I was hoping there was a few others around here that could help me out.

My script:

Code:
error_reporting(E_ALL | E_STRICT);
$max_execution_time = ini_get( 'max_execution_time' );
require("updatef.php");
mysql_connect("localhost","myusername","mypassword") or die(mysql_error());
mysql_select_db("hlallian_rank") or die(mysql_error());
//After Connection
$result1 = mysql_query("SELECT name, rank FROM guild") or die(mysql_error());
while ($row1 = mysql_fetch_array($result1, MYSQL_ASSOC))
    {
    $char = $row1['name'];
    // echo "<br/>updating $char";
    $searchStatus = getCharData($char, $charData);
    $exppercent = sprintf('<br>%.2F', $charData['expPercent']).'%';
    mysql_query("UPDATE guild SET class='{$charData['jobImageURL']}', avatar='{$charData['characterImageURL']}', pet='{$charData['petImageURL']}', level='{$charData['level']}', exp='{$charData['experience']}', percent='{$exppercent}', rank='{$charData['rank']}' WHERE name='{$char}'")or die(mysql_error());
    set_time_limit( $max_execution_time );
    }

Updatef.php contains the functions that fetches the data from the website, using regular expressions and preg_match.


Php / MySQL update script sending empty response - GummyBear - 2011-02-23

Quote:Updatef.php contains the functions that fetches the data from the website, using regular expressions and preg_match.

Quote:always gives me "(52) Empty reply from server" (using curl).

What you posted seems (almost) fine. The problem would likely to be the line $searchStatus = getCharData($char, $charData); which exists in require("updatef.php");

Chances are the IP got blocked or they update the website so that your regex no longer works (im leaning towards the 2nd possibility more).


Php / MySQL update script sending empty response - XTOTHEL - 2011-02-23

Modify your updatef.php so it prints out data without connecting to the database. I suspect the problem is there.


Php / MySQL update script sending empty response - Toastyc12 - 2011-02-23

GummyBear Wrote:What you posted seems (almost) fine. The problem would likely to be the line $searchStatus = getCharData($char, $charData); which exists in require("updatef.php");

Chances are the IP got blocked or they update the website so that your regex no longer works (im leaning towards the 2nd possibility more).

The regex is fine. I can add or remove individual members just fine using the same functions. The problem lays more with the whole script taking too long to do a batch operation, or at least, that's what I assume the problem to be. The line $searchStatus does not exist in Updatef.php, it links to the function getCharData which does.

$SearchStatus is what gathers the results for each row fetched rom MySQL, and returns as an array to be stored into the corresponding row. It's a necessary part of the loop. I cannot put the functions inside the loop either, as functions can only be declared once.
XTOTHEL Wrote:Modify your updatef.php so it prints out data without connecting to the database. I suspect the problem is there.

so should I gather the results before connecting to the database to store them? I'll look into this, but I'm not exactly sure how to store the results until they get transferred into the database.


Php / MySQL update script sending empty response - GummyBear - 2011-02-23

Toastyc12 Wrote:The line $searchStatus does not exist in Updatef.php, it links to the function getCharData which does.

I think I know my PHP thank you very much. It is blatantly obvious from your code and from my post what I referred to.

Toastyc12 Wrote:$SearchStatus is what gathers the results for each row fetched rom MySQL, and returns as an array to be stored into the corresponding row. It's a necessary part of the loop. I cannot put the functions inside the loop either, as functions can only be declared once.

From the given code, my guess is that $searchStatus is a boolean, $char is the name of the character and $charData seems to be a reference to an array where the function getCharData stores the data. Given that is all the code you're posting, not much to go on with. If you think the problem lies with the script taking too long, try increase the max execution time, tho, I got a feeling that it is something else, since you mentioned it only happened after server upgrade. Hard to say anything else without seeing more.