php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34483 FSockOpen + MYSQLI = CRASH!
Submitted: 2005-09-12 20:38 UTC Modified: 2005-09-12 23:48 UTC
From: javervandrel at yahoo dot com Assigned:
Status: Not a bug Package: Apache2 related
PHP Version: 5.0.5 OS: Windows 2000 Server
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: javervandrel at yahoo dot com
New email:
PHP Version: OS:

 

 [2005-09-12 20:38 UTC] javervandrel at yahoo dot com
Description:
------------
I'm writing a script that checks a MYSQL database for all ports that are currently assigned for shoutcast, then in a loop I'm opening each of those connections, pulling the data on the stream (is it broadcasting, if so what is the song title).  Then I'm updating that row in the DB with the appropriate info.  The script works, but every 24 hours or sometimes less the mysqli functions stop working, DB connections stop working, the only way to solve this is to STOP apache, wait a few seconds then start again (Restarting does not work, must be stop, wait, then start).  I cant find anybody out there having similar issues at all.  I tried using PHP 4.3+, 5.0+, and now 5.1 RC1, and it still happens.  Any help is greatly appreciated, thanks!

Reproduce code:
---------------
function sc_status($server, $port, $file) 
{
	$cont = "";
	$fp = fsockopen($server, $port, $errno, $errstr, 1);
	if (!$fp)
	{
		fclose($fp);
		return-2;
	}
	else
	{
		$com = "GET $file HTTP/1.1\r\nAccept: */*\r\nAccept-Language: de-ch\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\nHost: $server:$port\r\nConnection: Keep-Alive\r\n\r\n";
		fputs($fp, $com);
		while (!feof($fp))
		{
			$cont .= fread($fp, 500);
		}
		fclose($fp);
		$cont = substr($cont, strpos($cont, "\r\n\r\n") + 4);
	}

	fclose($fp);
	$parts = explode(',', $cont);
	return $parts;
}

include("dbopen.php");
$query="select port, name, username, id from djlist order by id DESC";
$stations=mysqli_query($chandle,$query);

echo "STARTS HERE<br><br>";

while(($temprow=mysqli_fetch_row($stations)) && ($continue != 6))
{
	$port=$temprow['0'];
	$name=$temprow['1'];
	$uname=$temprow['2'];
	$id=$temprow['3'];

	$value=sc_status('localhost', $port, '/7.html');

	$song=$value['6'];

	$online=$value['1'];

	if($song == "</body></html>")
		$online = 0;

	if($online != 0)
	{
		echo $song."<br>";
		$query="UPDATE djlist set song='".$song."', online=1 where id=$id";
		mysqli_query($chandle,$query);
	}
	else
	{
		$query="UPDATE djlist set online=0 where id=$id";
		mysqli_query($chandle,$query);
	}
}
mysqli_close($chandle);


Expected result:
----------------
STARTS HERE

Chamillionaire - Turn It Up
Elton John - Have Mercy On The Criminal
done

Actual result:
--------------
Unable to connect to Database.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-12 23:30 UTC] sniper@php.net
a) Provide a _short_ but _complete_ example script
b) Try this on a real OS, like Linux

 [2005-09-12 23:32 UTC] javervandrel at yahoo dot com
The script that I provided is the exact script that i'm using.  It is complete.  I'm using a real OS (windows).  Basically i'm looping through a bunch of different ports, for example the results of the query would be

8000
8050
8060
8070.....

This fsockopen loop could happen 15 times, each time it closes itself after getting the info, updates the DB, then does another instance of the loop.
 [2005-09-12 23:40 UTC] sniper@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.

include("dbopen.php"); <-- where's that?
How do you think we can try reproducing this if we don't know the database we should apparently have created?
 [2005-09-12 23:43 UTC] javervandrel at yahoo dot com
oh i'm sorry, the problem i'm having though is that this script causes the mysqli functions to stop working after about 24 hours of this script running.  It does not happen instantly, so I cannot provide a script that instantly causes the same error.  I figured the issue was probably a bug in the fclose or fsockopen methods where the stream is not being properly closed.
 [2005-09-12 23:46 UTC] sniper@php.net
You gotta be joking. Running a PHP for 24hours (under windows) is REALLY not supported or suggested. It's definately nothing to do with PHP but your OS.
 [2005-09-12 23:48 UTC] javervandrel at yahoo dot com
this script does not run for 24 hours, it runs for about 4-5 seconds before it completes, then the script using a HTML meta refresh restarts itself every 1 minute.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 05 09:01:29 2024 UTC