how to fix lots of warning message and MySQL server has gone away.

[php]

PHP Error Message

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a9655378/public_html/Insert_new_prices.php on line 97

PHP Error Message

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a9655378/public_html/Insert_new_prices.php on line 97

PHP Error Message

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a9655378/public_html/Insert_new_prices.php on line 97

Free Web Hosting

PHP Error Message

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a9655378/public_html/Insert_new_prices.php on line 97

PHP Error Message

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a9655378/public_html/Insert_new_prices.php on line 97

PHP Error Message

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a9655378/public_html/Insert_new_prices.php on line 97

PHP Error Message

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a9655378/public_html/Insert_new_prices.php on line 97

PHP Error Message

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a9655378/public_html/Insert_new_prices.php on line 97

PHP Error Message

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a9655378/public_html/Insert_new_prices.php on line 97

PHP Error Message

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a9655378/public_html/Insert_new_prices.php on line 97

Error in the query
MySQL server has gone away
[/php]

how to fix the above errors and the MySQL server has gone away error in my script?

If you script takes a long time to run it’s possible for the connection to timeout. I have used mysql_ping() before to keep a connection alive.

Thanks for the repply Matt,

my script indeed takes a long time excuting since it getch lot of data from an external site.

i tried the below code at the top of the my script is not working thought
[php]
ini_set(‘max_execution_time’, 300); //300 seconds = 5 minutes
ini_set(‘mysql.connect_timeout’, 300); //300 seconds = 5 minutes
ini_set(‘default_socket_timeout’, 300); //300 seconds = 5 minutes
[/php]

What is the wait_timeout value set to?

[php]SELECT @@wait_timeout;[/php]

i dont have that

wait_timeout is a mysql system variable.

http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_wait_timeout

the default is 28800 (8 hours) but it can be changed. one of my servers has it changed to 1800

just in case you are curious, this is the the whole script.
[php]

<?php /* this script will fetch all overloads prices and insert a new record on the database with the new price */ ini_set('max_execution_time', 300); //300 seconds = 5 minutes ini_set('mysql.connect_timeout', 300); //300 seconds = 5 minutes ini_set('default_socket_timeout', 300); //300 seconds = 5 minutes //if prices are wrong change the indexes $items_indexes = array(2,22,42,62,82,100,120,123,127,143); $items = array ( 'sAttack' => 'http://services.runescape.com/m=itemdb_rs/results.ws?page=1&query=super%20attack&sup=All&cat=All&vis=1&order=1&sortby=name&price=all&members=', 'sStrength' => 'http://services.runescape.com/m=itemdb_rs/results.ws?page=1&query=super%20strength&sup=All&cat=All&vis=1&order=1&sortby=name&price=all&members=', 'sDefence' => 'http://services.runescape.com/m=itemdb_rs/results.ws?page=1&query=super%20defence&sup=All&cat=All&vis=1&order=1&sortby=name&price=all&members=', 'Ranging' => 'http://services.runescape.com/m=itemdb_rs/results.ws?page=1&query=ranging%20potion&sup=All&cat=All&vis=1&order=1&sortby=name&price=all&members=', 'Magic' => 'http://services.runescape.com/m=itemdb_rs/results.ws?page=1&query=magic%20potion&sup=All&cat=All&vis=1&order=1&sortby=name&price=all&members=', 'Mud_runes' => 'http://services.runescape.com/m=itemdb_rs/results.ws?page=1&query=mud%20runes&sup=All&cat=All&vis=1&order=1&sortby=name&price=all&members=', 'Grenwall' => 'http://services.runescape.com/m=itemdb_rs/results.ws?page=1&query=grenwall&sup=All&cat=All&vis=1&order=1&sortby=name&price=all&members=', 'Avantoe' => 'http://services.runescape.com/m=itemdb_rs/results.ws?page=1&query=avantoe&sup=All&cat=All&vis=1&order=1&sortby=name&price=all&members=', 'Dwarfweed' => 'http://services.runescape.com/m=itemdb_rs/results.ws?page=1&query=dwarf%20weed&sup=All&cat=All&vis=1&order=1&sortby=name&price=all&members=', 'Lantadyme' => 'http://services.runescape.com/m=itemdb_rs/results.ws?page=1&query=lantadyme&sup=All&cat=All&vis=1&order=1&sortby=name&price=all&members=', ); foreach ($items as $url) { $html = file_get_contents_curl($url); //parsing begins here: $doc = new DOMDocument(); @$doc->loadHTML($html); // HTML tags look for $div_elements = $doc->getElementsByTagName('td'); if ($div_elements->length <> 0) { foreach ($div_elements as $div_element) { //emelent class name if ($div_element->getAttribute('class') == 'price') { $prices[] = DOMinnerHTML($div_element); } } } } //print_r($prices); foreach ($items_indexes as $key) { $rPrices[] = str_replace(',','',$prices[$key]); } date_default_timezone_set('US/Eastern'); $fulldate = date("D, d M Y - h:i:s a"); // foreach ($rPrices as $value) // { mysql_query("INSERT INTO `overload` VALUES ('".time()."','$fulldate','$rPrices[0]','$rPrices[1]','$rPrices[2]','$rPrices[3]','$rPrices[4]', '$rPrices[5]','$rPrices[6]','$rPrices[7]','$rPrices[8]','$rPrices[9]')") or die("Error in the query
".mysql_error()); // } // foreach ($rPrices as $value) // { // echo $value."
"; // } $total = 0; for ($i=0; $ichildNodes; foreach ($children as $child) { $tmp_dom = new DOMDocument(); $tmp_dom->appendChild($tmp_dom->importNode($child, true)); $innerHTML.=trim($tmp_dom->saveHTML()); } return $innerHTML; } ?>

[/php]

you can see all the warnings at http://wilson382.info/cronjob/Insert_new_prices.php

the MySQL server has gone away error i oly get it sometimes but the others warning i always get them.

this is cronjob script

Do you need to use CURLOPT_FOLLOWLOCATION? If you don’t expect any header(‘Location: …’) redirects then you should remove it from the curl request. If you google the error the first result may have some helpful information:

As far as the mysql timeout. I would say you need to either open the connection after all URLs are parsed OR insert the results after each URL. For example:

[php]
$prices = array(); // reset $prices array
if ($div_elements->length <> 0) {
foreach ($div_elements as $div_element) {
if ($div_element->getAttribute(‘class’) == ‘price’) {
$prices[] = DOMinnerHTML($div_element);
}
}
}
if ($prices) {
// loop $prices and insert values
}
[/php]

I’m also curious about your DOMinnerHTML() function. If you only need to get the value, couldn’t you just use textContent? e.g.

[php]
if ($div_element->getAttribute(‘class’) == ‘price’) {
$prices[] = $div_element->textContent;
}
[/php]

yea i had redundant codes i did not need the extra function.

as MySQL server has gone away error it fixed by not opening the connection at the top of the script.

now all i need get rid of warnings.

by removing the below line should fix it?

[php]
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
[/php]

also since i was using a function that i did not need should it run faster now? it usally takes 11-14 seconds to execute the whole script.

Yes you should be able to remove CURLOPT_FOLLOWLOCATION. I tested it and there were no redirects on your URLs.

The speed improvement is probably minimal but it will certainly use less memory.

thank you for your help Matt, really appreciated.

Sponsor our Newsletter | Privacy Policy | Terms of Service