What is better for the code segment, sockets or multiple processes? I am trying to fetch information out of SHOUTcast for mutiple users at the same time. Here is my current code:

&lt;?php
    header("Access-Control-Allow-Origin:*");

    function failOut($http, $text) {
        header('HTTP/1.x ' . $http);
        die(htmlspecialchars($text));
    }

    $params = $_GET;
    $user = 'root'; // Change this to username
    $password = ''; // Put your password here. My home database doesn't have any password (is empty).

    $con = mysql_connect('localhost',$user,$password) or die('Could Not Connect..');

    $context = stream_context_create(
        array(
            'http' =&gt; array(
                //Required To fool ShoutCast or it will flood with the stream instead
                'user_agent' =&gt; "GET / HTTP/1.0\r\n"
                            ."Host:117.200.149.48\r\n"
                            ."User-Agent: Mozilla/5.0 (compatible; ShoutCastInfoClass/0.0.2; ".PHP_OS.")\r\n"
                            ."\r\n",
            ),
        )
    );

    if($params['act'] == 'st'){
        mysql_select_db('radio',$con);
        $count = mysql_query("select * from info where ID='".$params['id']."'")or die('Error In Query'.mysql_error());

        $content = null;
        $rows = mysql_num_rows($count);
        if( $rows &gt; 0 ){
            $res = mysql_fetch_assoc($count);

            if($res['TIMESTAMP'] + 30 &lt; time()){
                if($res['version'] == '1'){
                    $base = $res['IP'].'/admin.cgi?mode=viewxml&amp;user=admin&amp;pass='.$res['PASS'];
                    // Well i will change this crazy method with something non password secured pretty soon
                }else{
                    $base = $res['IP'].'/stats?sid=1';
                    // As per shoutcast v2 APIs !! :D
                }
                $content = file_get_contents($base, false, $context)or die("Unable to Load resourse");
                $dom = new DOMDocument();
                $dom-&gt;loadXML($content);
                $res['SERVERTITLE'] =  htmlspecialchars($dom-&gt;getElementsByTagName('SERVERTITLE')-&gt;item(0)-&gt;textContent);
                $res['SONGTITLE'] = htmlspecialchars( $dom-&gt;getElementsByTagName('SONGTITLE')-&gt;item(0)-&gt;textContent );
                $res['BITRATE'] = $dom-&gt;getElementsByTagName('BITRATE')-&gt;item(0)-&gt;textContent;
                $res['GENRE'] = $dom-&gt;getElementsByTagName('SERVERGENRE')-&gt;item(0)-&gt;textContent;
                $res['CONTENT'] = $dom-&gt;getElementsByTagName('CONTENT')-&gt;item(0)-&gt;textContent;

                if(strpos($res['CONTENT'],'mpeg')){
                    $res['CONTENT'] = 'MP3';
                }else if(strpos($res['CONTENT'],'aac')){
                    $res['CONTENT']= 'AAC';
                }else{
                    $res['CONTENT'] = 'OGG';
                }
                $query='update INFO SET SERVERTITLE="'.$res['SERVERTITLE'].
                '", SONGTITLE="'.$res['SONGTITLE'].
                '", BITRATE="'.$res['BITRATE'].
                '", GENRE="'.$res['GENRE'].
                '", CONTENT="'.$res['CONTENT'].
                '" , TIMESTAMP='.time().' where ID=\''.$params['id']. '\';';
                mysql_query($query,$con)or die(mysql_error());
                mysql_close($con);
            }
            unset( $res['IP'] );
            unset( $res['PASS'] );
            echo json_encode($res);
        }
    }else if($_params['act']== 's'){
        // To search for a specific keyword
        $queryString = $params['q'];
    }else if($_params['act'] == 'l'){
        // To feed list to the applet
        $cat = $params['c'];
        // Categories are various lists depending on genre languages etc...
    }
?&gt;


I was wondering if making a phpSocket server would be better for this purpose as sockets will reduce the demand of required MySQL connections to be opened.

Or

Is my current method the best solution?
If you want to use this function you should have buffering:


function failOut($http, $text) {
    header('HTTP/1.x ' . $http);
    die(htmlspecialchars($text));
}



Otherwise it's possible that the script sends out some output (including error messages) and you can't send out any header later. (How do headers work with output buffering in PHP?) Anyway, I don't see any call to this function, so you might be able to remove it.

$con = mysql_connect('localhost',$user,$password) or die('Could Not Connect..');



As others already suggested you should use mysqli or PDO. Another note is that you might want to set the HTTP response code to 503 here to save your search engine ranking when the database is down.

$params = $_GET; 
...
$count = mysql_query("select * from info where ID='".$params['id']."'")or die('Error In Query'.mysql_error()); 



As others already mentioned in comments it's not safe against SQL injections attacks. mysql_error() should not be the output of the script. Show only a generic error message and log the details to a server-side log file, don't help attackers. It would also be more user-friendly, most of the users doesn't care nor understand MySQL errors (or at least can't fix them). (How to log errors and warnings into a file?)

$dom-&gt;getElementsByTagName('BITRATE')-&gt;item(0)-&gt;textContent



This is in the code at least five times (with different tagname). You could create a function (whose parameter is the tagname) to remove the duplication.