Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP script issue

Posted on 2010-09-06
28
Medium Priority
?
825 Views
Last Modified: 2012-05-10
Hi there experts!

Got a problem regarding my virtual server which is running CentOS 5.5 with webmin, all modules such as httpd, mysql, mysql-server all up-to-date.

I have a php script that interfaces with a virtual world called Second Life, the purpose of this script is to allow the webserver to interface with the secondlife script, which is set to listen for specific commands.

After trying multiple times, running a whole different distro of linux thinking that was the issue, i've came to a complete stop.

This php script works with a friends webserver, although running plesk and hosted for him by a hosting provider, i'm completely self hosted, his script works without a problem, yet when i attempt to do the same, the php page hangs for a long while (not crash style) then EVENTUALLY refreshes, like it completed the request...yet it hasn't.

Looking at the error_log i find nothing of issue, although my knowledge is rather limited so having alot of new eyes looking this over might show me the issue, and possible resolution.

Below is how i operate the script and what results i expect to have it achieve:

Webserver provides php page with a list of objects in second life, that have contacted the webserver with its, unique identifer masks, world location, time it last contacted etc.

I select one and check a box labelled set text and enter "Hello World", then hit send, which SHOULD have floating text above the object in secondlife with "Hello World"

Yet instead it hangs...then does nothing, my friends webserver using the same script, however does this and the changes becomes apparant immediately.

Here is what the URL looks like: (Friends webserver using plesk, has kindly provided phpinfo, though looks greek to me for the most part)

http://paintballpalmer.com/sls1/manageserver.php?xml=70b92dc6-0c4d-630e-b32f-c084e7c9adec&slcmd=st&settext=Hello+World+411&cmd=Send

^ - this would change the selected objects floating text, however when i use that on my webserver, changing the domain name to an IP (no domain name hosting, just IP) the hang occurs.

Not sure what else to provide, however if you require anything else then i will gladly give the information, there may be some delay between responses due to work related matters, yet i do check in regularly so do not think i'm...how to put it....not serious about this or something, because i very much am.

Hope to hear from you all soon experts!

P.S - to further the possible understanding to resolution, i have provided the code for the servers.php of my server to see if there is any obvious issues i may have overlooked.


<?
session_start();

if (empty($_SESSION['user']))
{
    header("location:login.php");
}
include("lib/_mysql.php");
?>
<?

function do_xml_post($data_channel, $data_int, $data_string)
{
    $service_port = getservbyname('www', 'tcp');
    $address = gethostbyname('xmlrpc.secondlife.com');
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    $result = socket_connect($socket, $address, $service_port);

    $data = "<?xml version=\"1.0\"?><methodCall><methodName>llRemoteData</methodName><params><param><value><struct><member><name>Channel</name><value><string>$data_channel</string></value></member><member><name>IntValue</name><value><int>$data_int</int></value></member><member><name>StringValue</name><value><string>$data_string</string></value></member></struct></value></param></params></methodCall>";

    $in = "POST /cgi-bin/xmlrpc.cgi HTTP/1.1\r\n";
    $in .= "Accept: */*\r\n";
    $in .= "Accept-Language: en-gb\r\n";
    $in .= "Cache-control: no-cache\r\n";
    $in .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $in .= "Host: xmlrpc.secondlife.com\r\n";
    $in .= "Content-Length: " . strlen($data) . "\r\n\r\n";
    $in .= $data;
    socket_write($socket, $in, strlen($in));
    socket_close($socket);
}

if ($_GET['cmd'] == "del")
{
    $idtodelete = $_GET['id'];
    $getsql = "DELETE FROM `sls_servers` WHERE sid=$idtodelete";
    $getqry = mysql_query($getsql) or die(mysql_error());
} else if ($_GET['cmd'] == "Send")
{
    $select = $_REQUEST['select'];
    $slcmd = $_GET['slcmd'];
    if ($_GET['sendall'] == "yes")
    {
        if ($slcmd == "kill")
        {
            $integer_var = 1;
        } else if ($slcmd == "reset")
        {
            $integer_var = 2;
        } else if ($slcmd == "st")
        {
            $string_var = $_GET['settext'];
            $integer_var = 6;
        } else if ($slcmd == "store")
        {
            $integer_var = 3;
        } else if ($slcmd == "disable")
        {
            $integer_var = 4;
        } else if ($slcmd == "enable")
        {
            $integer_var = 5;
        }
        $getsql = "SELECT sxml FROM `sls_servers`";
        $getqry = mysql_query($getsql) or die(mysql_error());
        while ($row = mysql_fetch_assoc($getqry))
        {
            do_xml_post($row['sxml'], $integer_var, $string_var);
        }
        echo "OK.";
        if ($integer_var == 1)
        {
            $getsql = "TRUNCATE TABLE sls_servers";
            $getqry = mysql_query($getsql) or die(mysql_error());
        }
    } else
    {
        if ($slcmd == "kill")
        {
            $integer_var = 1;
            $idtodelete = $_GET['select[]'];
            $getsql = "DELETE FROM `sls_servers` WHERE `sxml`='$idtodelete'";
            $getqry = mysql_query($getsql) or die(mysql_error());
        } else if ($slcmd == "reset")
        {
            $integer_var = 2;
        } else if ($slcmd == "st")
        {
            $string_var = $_GET['settext'];
            $integer_var = 6;
        } else if ($slcmd == "store")
        {
            $integer_var = 3;
        } else if ($slcmd == "disable")
        {
            $integer_var = 4;
        } else if ($slcmd == "enable")
        {
            $integer_var = 5;
        }
        /*
         * This is so that all the checked servers get the message
         */
        foreach ($select as $selectname)
        {
            do_xml_post($selectname, $integer_var, $string_var);
        }
    }
} else if ($_REQUEST['cmd'] == "store")
{
	$serverstable = "sls_servers";
    $slsname = $_GET['name'];       // Name of the object
    $slskey = $_GET['key'];         // The sl UUID of the obj
    $slsregion = $_GET['region'];   // Name of the Region containing the obj
    $slsxml = $_GET['xml'];         // XML-RPC "channel"
    $slspos = $_GET['pos'];         // Vector position of the obj
    $slstime = $_GET['time'];       // Time in secs since unix epoch
    $slsid = $_GET['id'];           // Random ID generated by the object
    //The following lines add the
    $getsql = "REPLACE INTO `" . $serverstable . "` (`sname`, `skey`, `sxml`, `sregion`, `spos`, `stime`, `sid`) VALUES ('" . $slsname . "', '" . $slskey . "',  '" . $slsxml . "', '" . $slsregion . "', '" . $slspos . "', '" . $slstime . "', '" . $slsid . "')";
    $getqry = mysql_query($getsql) or die(mysql_error());
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title> SLSM &nbsp; :|: &nbsp; V1.5 </title>
        <!-- Javascript - Fix the flash of unstyled content -->
        <script type="text/javascript"></script>
        <script type="text/javascript" src="jquery-1.4.min.js"></script>
        <script type="text/javascript">
            function FillForm(xml) {
                $("#xmlrpc").val(function(i, v)
                { return xml });
            }
        </script>

        <!-- Stylesheets -->
        <link href="css/reset.css" rel="stylesheet" type="text/css" media="all" />
        <link href="css/default.css" rel="stylesheet" type="text/css" media="screen" />
        <link href="css/styling.css" rel="stylesheet" type="text/css" media="screen" />
        <!-- Print Stylesheet -->
        <link href="css/print.css" rel="stylesheet" type="text/css" media="print" />

        <!-- Meta Information -->
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
        <meta http-equiv="imagetoolbar" content="no" />
        <meta http-equiv="cache-control" content="public" />
        <meta http-equiv="pragma" content="no-cache" />
        <meta http-equiv="expires" content="never" />
        <meta name="language" content="en-gb" />
        <meta name="MSSmartTagsPreventParsing" content="true" />
        <meta name="robots" content="index, follow" />
        <meta name="revisit-after" content="14 days" />
        <meta name="author" content="Mitchell Bryson" />

        <meta name="keywords" content="" />
        <meta name="description" content="" />

    </head>
    <body>

        <div id="container">
            <div id="header">
                <div id="header-in">
                    <?php include "lib/header.php"; ?>
                </div> <!-- end #header-in (provides padding)-->
            </div> <!-- end #header -->

            <div id="content-wrap" class="clear lcol">
                <div class="column">
                    <div class="column-in">
                        <?php include "lib/nav.php"; ?>
                    </div> <!-- end .column-in -->
                </div> <!-- end .column -->

                <div class="content">
                    <div class="content-in">
                        <h1> Server Management</h1>
                        <form action="" method="get" enctype="application/x-www-form-urlencoded" name="form1" id="form1">
                            <?
                            $getsql = "SELECT * FROM `sls_servers`";
                            $getqry = mysql_query($getsql) or die(mysql_error());
                            if (mysql_num_rows($getqry) > 0)
                            {
                                echo "<table width='100%' border='1'>";
                                echo "<td>ID</td>";
                                echo "<td>Server Name</td>";
                                echo "<td>Key</td>";
                                echo "<td>Region</td>";
                                echo "<td>Position</td>";
                                echo "<td>Last Seen</td>";
                                echo "<td>Select</td>";
                                $res = $getqry;
                                while ($row = mysql_fetch_assoc($res))
                                {
                                    $slsid = $row['sid'];
                                    $slsname = $row['sname'];
                                    $slskey = $row['skey'];
                                    $slsregion = $row['sregion'];
                                    $slspos = $row['spos'];
                                    $stime = $row['stime'];
                                    $slsxml = $row['sxml'];

                                    $offset = (time() + 480) - $stime;
                                    $slstime = round(($offset) / 60, 2);

                                    //echo vars . php . get("checkInTime");

                                    //if ($offset > vars . php . get("checkInTime") + 60)
                                    //{
                                    //    $getsql = "DELETE FROM `sls_servers` WHERE `sid` = '$slsid'";
                                    //    $getqry = mysql_query($getsql) or die(mysql_error());
                                    //} else
                                    //{
                                        echo "<tr>\n";
                                        echo "<td>$slsid</td>\n";
                                        echo "<td>$slsname</td>";
                                        echo "<td>$slskey</td>";
                                        echo "<td>$slsregion</td>";
                                        echo "<td>$slspos</td>";
                                        echo "<td>$slstime min</td>";

                                        //echo "<td><a href=\"#\" onClick=\"javascript:FillForm('" . $slsxml . "');return false;\"><img src=\"img/tick.gif\" border=\"0\"></a></td>\n";
                                        //echo "<td> <button onClick=\"javascript:FillForm(\'hehe\');return false;\">Input</button></td>";
                                        echo "<td><center><input type=\"checkbox\" name=\"select[]\" value='" . $slsxml . "'/></center></td>";
                                        //echo "<td><a href=\"servers.php?cmd=del&id=$slsid\" OnClick=\"return confirm('Are you sure you want to delete $slsname? The server will be unavailable until it next syncronises.');\"><img src=\"img/cross.gif\" border\"0\"></a></td>";
                                        echo "</tr>";
                                    }
                                //}
                                echo "</table>";
                            } else
                            {
                                echo "No servers.";
                            }
                            ?>

                            <p>Server Options</p>
                            <p>
                                <!--<label for="id">RPC Channel</label>
                                <input name="xml" type="text" id="xmlrpc" readonly="readonly" />-->

                                <label>
                                    <input type="radio" name="slcmd" value="kill" id="RadioGroup1_0" />
                                    Kill - Warning: This will destroy the object!</label>
                                <br />

                                <label>
                                    <input type="radio" name="slcmd" value="reset" id="RadioGroup1_1" />
                                    Reset</label>
                                <br />

                                <label>
                                    <input type="radio" name="slcmd" value="disable" id="RadioGroup1_1" />
                                    Disable</label>
                                <br />

                                <label>
                                    <input type="radio" name="slcmd" value="enable" id="RadioGroup1_1" />
                                    Enable</label>
                                <br />

                                <label>
                                    <input type="radio" name="slcmd" value="store" id="RadioGroup1_2" />
                                    Update Information</label>
                                <br />

                                <label>
                                    <input type="radio" name="slcmd" value="st" id="RadioGroup1_2" />
                                    Set Text</label>

                                <label>
                                    <input type="text" name="settext" id="settext" />
                                </label>
                            </p>
                            <label>
                                <input type="checkbox" name="sendall" value="yes" id="sendall_0" />
                                Send to All (May take a while)</label>
                            <br />
                            <label for="submit"></label>
                            <input type="submit" name="cmd" id="cmd" value="Send" />
                        </form>
                        <p>&nbsp;</p>
                    </div> <!-- end .content-in -->
                </div> <!-- end .content -->
            </div> <!-- end #content-wrap
            <div class="clear"></div>-->
            <div id="footer">
                <div id="footer-in">
                    <?php include "lib/footer.php"; ?>
                </div> <!-- end #footer-in -->
            </div> <!-- end #footer -->
        </div> <!-- end div#container -->
    </body>
</html>

Open in new window

0
Comment
Question by:JayRitchie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 16
  • 12
28 Comments
 

Author Comment

by:JayRitchie
ID: 33614301
Oh in addition, my server is the following:

http://81.19.212.250/

Default, login credentials

User: Admin
Pass: 1234

Not sure if this is appropriate yet i'm really wanting to understand this issue, because it has stumped me for quite a while, so trying to give you all as much understanding as possible, next step would probably be screenshots!

Thanks again!
0
 
LVL 9

Expert Comment

by:absx
ID: 33615181
Hi,

"Completely self hosted", error only occurring with numeric IP address URL and script doing a lot of gethostbyname() would point to a DNS configuration issue on the server. Tried the service with the provided link, and it seemed very responsive and snappy, though. Is this issue still ongoing?
0
 

Author Comment

by:JayRitchie
ID: 33615284
Yes, the issue is very much ongoing.

If it requires the need for a domain name then i should be able to set it up with one, however would have thought that numeric IP address URL's would be sufficient.

Isn't there a way to have it use just the IP address as the URL, or is it because of this lack of domain name that is causing it.

The IP address link to the web interface, brings it up fine, however once you login with the default credentials, select a server on the list, and try and either set text or any other option and click send, the PHP script hangs.
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 9

Expert Comment

by:absx
ID: 33615316
Hi,

As a general solution to "I'm not sure which part is causing the delay" problems, I suggest the following test method.

On the first line, place this:
  $starttime = microtime(true);

After suspicious commands (or every line if unsure), paste this line:
 echo "Runtime : ".round(microtime(true)-$starttime,3)." seconds, current line: ".__LINE__."<br />\n";

This should give you a nice printout of the timed script run and point the slow parts.
0
 
LVL 9

Expert Comment

by:absx
ID: 33615329
Oh,

And there should be no need to register a domain name for the host. It's just that if there's no DNS reverse available and gethostbyname calls are used, the "no name available" responses might cause unexpected behaviour. The lack of reverse/domain nome should also be noted when configuring Apache.

Also, you might want to test by commenting out the "getservbyname" and "gethostbyname" functions and just giving it the real IP address and default HTTP port 80 instead.

- Jarkko
0
 

Author Comment

by:JayRitchie
ID: 33615526
Ah,

Well i'm not exactly competent with PHP just yet, however i'll try those steps when at the server and see what the outcome is.

In regards to Apache being configured for lack of reverse/domai names, what configuration would i modifying to show this, httpd.conf or something else, and what specifically would i be modifying?

Cheers
0
 
LVL 9

Expert Comment

by:absx
ID: 33615638
Ok,

I re-read the original issue and realised that the delay doesn't occur between your client and your server but instead only when the server is trying to issue the HTTP request with xmlrpc.secondlife.com. Therefore your Apache configuration should be fine.

The timing test should give a clue on where to look. The most likely sure-fire solution would be to replace the custom TCP communication and self-monitored socket operations with tried-and-tested CURL functions, but let's see the timing results and error messages first.
0
 

Author Comment

by:JayRitchie
ID: 33615826
Alright, sounds like a plan.

I'll put that timing test in and see what turns up, just to confirm i'm putting:

echo "Runtime : ".round(microtime(true)-$starttime,3)." seconds, current line: ".__LINE__."<br />\n";

after every suspect line in the code snippet attached with my original question?
0
 
LVL 9

Expert Comment

by:absx
ID: 33615973
Hi,

Yeah, that should give an idea of what's going on. The site xmlrpc.secondlife.com resolves into four different IP addresses: 216.82.16.12, 216.82.16.11, 216.82.16.14 and 216.82.16.13. The default is .12. I tested with a CURL implementation I found (attached) and the same request took 80(!) seconds on the default server, whereas calling .13 directly (as in supplying the real IP instead of the hostname) the same request went through in 12 seconds. Maybe this could be a solution?


<?
function sendrpc($chan, $intval, $strval, $url) {
  $req = xmlrpc_encode_request(
    "llRemoteData",
    array(
      "Channel"=>(string)$chan, 
      "IntValue"=>(int)$intval, 
      "StringValue"=>(string)$strval
    )
  );
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $reply = curl_exec($ch);
  curl_close($ch);

  $replyVars = xmlrpc_decode($reply);
  return $replyVars;
}

// Time limit needs to be big because of the first server being slow
set_time_limit(90);

// Hosts to test with
$urls = array(
  "http://xmlrpc.secondlife.com/cgi-bin/xmlrpc.cgi",
  "http://216.82.16.13/cgi-bin/xmlrpc.cgi"
);

foreach($urls as $url) {
  $starttime = microtime(true);
  sendrpc($url, "70b92dc6-0c4d-630e-b32f-c084e7c9adec", "st", "test");
  echo "Completed using $url in ".round(microtime(true)-$starttime,3)." seconds.<br />";
}
?>

Open in new window

0
 

Author Comment

by:JayRitchie
ID: 33616326
Really!?

I'll definately be looking into this when i get to the server later, was reading about CURL implementation but as with untested languages, i'm rather hesitant, but i'll look into that definately, will get back to you once i've tested this out!

All i know is that when i tried sending the information, while it took forever, the data actually never went through, as the float text above the in-world (secondlife) object never changed, so hopefully this could resolve that as well.
0
 

Author Comment

by:JayRitchie
ID: 33620744
Got the results of that microtime test here, put in the snippet to show where i placed the code

Results were:

Runtime : 1283885528.083 seconds, current line: 18
Runtime : 1283885721.033 seconds, current line: 20
Runtime : 1283885721.033 seconds, current line: 22
Runtime : 1283885721.033 seconds, current line: 32
Runtime : 1283885721.033 seconds, current line: 34

Will attempt something in regards to the curl code you posted now.
<?
$starttime = microtime(true);
session_start();

if (empty($_SESSION['user']))
{
    header("location:login.php");
}
include("lib/_mysql.php");
?>
<?

function do_xml_post($data_channel, $data_int, $data_string)
{
    $service_port = getservbyname('www', 'tcp');
    $address = gethostbyname('xmlrpc.secondlife.com');
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
echo "Runtime : ".round(microtime(true)-$starttime,3)." seconds, current line: ".__LINE__."<br />\n";
    $result = socket_connect($socket, $address, $service_port);
echo "Runtime : ".round(microtime(true)-$starttime,3)." seconds, current line: ".__LINE__."<br />\n";
    $data = "<?xml version=\"1.0\"?><methodCall><methodName>llRemoteData</methodName><params><param><value><struct><member><name>Channel</name><value><string>$data_channel</string></value></member><member><name>IntValue</name><value><int>$data_int</int></value></member><member><name>StringValue</name><value><string>$data_string</string></value></member></struct></value></param></params></methodCall>";
echo "Runtime : ".round(microtime(true)-$starttime,3)." seconds, current line: ".__LINE__."<br />\n";
    $in = "POST /cgi-bin/xmlrpc.cgi HTTP/1.1\r\n";
    $in .= "Accept: */*\r\n";
    $in .= "Accept-Language: en-gb\r\n";
    $in .= "Cache-control: no-cache\r\n";
    $in .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $in .= "Host: xmlrpc.secondlife.com\r\n";
    $in .= "Content-Length: " . strlen($data) . "\r\n\r\n";
    $in .= $data;
    socket_write($socket, $in, strlen($in));
echo "Runtime : ".round(microtime(true)-$starttime,3)." seconds, current line: ".__LINE__."<br />\n";
    socket_close($socket);
echo "Runtime : ".round(microtime(true)-$starttime,3)." seconds, current line: ".__LINE__."<br />\n";
}

if ($_GET['cmd'] == "del")
{
    $idtodelete = $_GET['id'];
    $getsql = "DELETE FROM `sls_servers` WHERE sid=$idtodelete";
    $getqry = mysql_query($getsql) or die(mysql_error());
} else if ($_GET['cmd'] == "Send")
{
    $select = $_REQUEST['select'];
    $slcmd = $_GET['slcmd'];
    if ($_GET['sendall'] == "yes")
    {
        if ($slcmd == "kill")
        {
            $integer_var = 1;
        } else if ($slcmd == "reset")
        {
            $integer_var = 2;
        } else if ($slcmd == "st")
        {
            $string_var = $_GET['settext'];
echo "Runtime : ".round(microtime(true)-$starttime,3)." seconds, current line: ".__LINE__."<br />\n";
            $integer_var = 6;
echo "Runtime : ".round(microtime(true)-$starttime,3)." seconds, current line: ".__LINE__."<br />\n";

Open in new window

0
 
LVL 9

Expert Comment

by:absx
ID: 33620912
Hi,

Looks like you forgot to initialize the starttime variable at the beginning of the script with
$starttime = microtime(true);
That would explain the high, descending numbers.

But the in-between times would indeed point to a slow server - shouldn't take 7 seconds for socket_connect() to finish.
0
 

Author Comment

by:JayRitchie
ID: 33621014
Sorry about that, updated it and it shows a more realistic number, same code position as before, results are:

Runtime : 0.003 seconds, current line: 19
Runtime : 193.04 seconds, current line: 21
Runtime : 193.04 seconds, current line: 23
Runtime : 193.041 seconds, current line: 33
Runtime : 193.041 seconds, current line: 35

So yeah....quite a long while, think it might be a socket connect issue...although thats just me assuming.
0
 
LVL 9

Accepted Solution

by:
absx earned 2000 total points
ID: 33621083
Yeah,

Light fix to my previous script below (parameters for function in the wrong order). Current test results return the output below - it seems your script isn't running, but assuming the SL scripting host timeout is 30 seconds, the communication between server and SL host only took half a second in both cases.


Testing with http://xmlrpc.secondlife.com/cgi-bin/xmlrpc.cgi... <br />
Completed using http://xmlrpc.secondlife.com/cgi-bin/xmlrpc.cgi in 30.514 seconds.<br />Results: array(2) {
  ["faultString"]=>
  string(48) "Script timeout: no response recieved from script"
  ["faultCode"]=>
  int(1)
}
Testing with http://216.82.16.13/cgi-bin/xmlrpc.cgi... <br />
Completed using http://216.82.16.13/cgi-bin/xmlrpc.cgi in 30.428 seconds.<br />Results: array(2) {
  ["faultString"]=>
  string(48) "Script timeout: no response recieved from script"
  ["faultCode"]=>
  int(1)
}

<?
function sendrpc($url, $chan, $intval, $strval) {
  $req = xmlrpc_encode_request(
    "llRemoteData",
    array(
      "Channel"=>(string)$chan, 
      "IntValue"=>(int)$intval, 
      "StringValue"=>(string)$strval
    )
  );
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $reply = curl_exec($ch);
  curl_close($ch);

  $replyVars = xmlrpc_decode($reply);
  return $replyVars;
}

// Time limit needs to be big because of the first server being slow
set_time_limit(90);
error_reporting(E_ALL);

// Hosts to test with
$urls = array(
  "http://xmlrpc.secondlife.com/cgi-bin/xmlrpc.cgi",
  "http://216.82.16.13/cgi-bin/xmlrpc.cgi",

);

foreach($urls as $url) {
  $starttime = microtime(true);
  echo "Testing with $url... <br />\n";
  $res = sendrpc($url, "70b92dc6-0c4d-630e-b32f-c084e7c9adec", 32, "test");
  echo "Completed using $url in ".round(microtime(true)-$starttime,3)." seconds.<br />";
  echo "Results: ";
  var_dump($res);
}

?>

Open in new window

0
 

Author Comment

by:JayRitchie
ID: 33621180
Pasted that script in to the servers.php, replacing the function_do_xml_post part, and the page just doesn't load at all, just hangs completely, seriously starting to think i'm missing some sort of module....or extension...or its blocked in some way...switched off the firewall and it still doesn't work properly.

This is the issue i had the last time...it just...freezes...does nothing, the inworld script is fine...just...the php part is the issue, i know THAT much.
0
 

Author Comment

by:JayRitchie
ID: 33622981
After having a friend look at it and manage to get it to work in windows apache, i ported it over to linux and the same issue occurs, hanging page then it recovers and does nothing.

He made the suggestion i might have a socket connection issue, and to look for php_sockets.so...or something to that effect....i cannot find that at all...would i be on the right track by assuming this, and if so, where do you normally acquire such a file?
0
 
LVL 9

Expert Comment

by:absx
ID: 33624411
Hi,

It would seem that if I disable the XMLRPC extension for PHP, the execution stops early and without errors with my example. So, installing the XMLRPC extension and switching the function to the CURL one I pasted earlier might be a solution.

- Jarkko
0
 

Author Comment

by:JayRitchie
ID: 33624512
The XMLRPC extension was already installed, I have a phpinfo file at http://81.19.212.250/sockettest.php . Tried your latest curl code you pasted and it just freezes the entire period, your previous curl code snippet to that, executes fine. Just seems like one problem after another, rather disheartening.
0
 
LVL 9

Expert Comment

by:absx
ID: 33624671
Hi,

Someone else was having a similar problem with their CentOS, here: http://forums.cacti.net/about32844.html&highlight=

It would seem, though, that the sockets extension is included in the package php-common, along with CURL, according to http://www.centos.org/modules/newbb/viewtopic.php?topic_id=11747&forum=37

- Jarkko
0
 

Author Comment

by:JayRitchie
ID: 33624738
Looking at my phpinfo file i found that when i yum installed php and curl, that -enable-sockets was used, so it would seem that for whatever reason my setup hates sockets connections, and your latest code snippet for the CURL example, however as i previously mentioned the previous CURL code snippet example worked...so something between those two just stops the page dead.
0
 
LVL 9

Expert Comment

by:absx
ID: 33633615
HI,

I'm afraid I've been busy elsewhere for a while. If the same code indeed works elsewhere, with similar Apache/PHP configurations (you've got "error_reporting = E_ALL" and "display_errors = on" in your php.ini, right?), it might be some kind of a firewall issue preventing the Apache process from creating sockets.

Simple test for this (live example for comparison at my server http://lolcathost.ath.cx/~absolut/test_socket.php):
<?php

$output = "";

$fp = fsockopen("www.google.com", 80, $errno, $errstr, 30);
if (!$fp) {
    $output .= "$errstr ($errno)<br />\n";
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: www.example.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        $output .= fgets($fp, 128);
    }
    fclose($fp);
}
echo htmlentities($output);
?>

Open in new window

0
 

Author Comment

by:JayRitchie
ID: 33634239
I've done it in the past with the firewall off, i'll try it again to see if it is actually that this time around.

Though if its not firewall related, then i'll be very confused as to why this is, will double check i have those error masks active.
0
 

Author Comment

by:JayRitchie
ID: 33641278
Switched off iptables and ip6tables (just in case) and then turned on display errors and error_reporting and found the following.

Notice: Undefined index: sendall in /var/www/html/servers.php on line 47

Warning: socket_connect() [function.socket-connect]: unable to connect [110]: Connection timed out in /var/www/html/servers.php on line 17

Warning: socket_write() [function.socket-write]: unable to write to socket [32]: Broken pipe in /var/www/html/servers.php on line 31

I believe i saw this before yet i never got anywhere with it as it was really specific and resolutions were left to your imagination.
0
 
LVL 9

Expert Comment

by:absx
ID: 33643622
Yeah,

The connection timeout would indeed point towards some network connectivity problem.
Can you ping the server? Can you "telnet xmlrpc.secondlife.com 80" to open a TCP connection?

- Jarkko
0
 

Author Comment

by:JayRitchie
ID: 33645122
Tried to telnet to xmlrpc.secondlife.com on port 80 with iptables off, doesn't connect, also tried to ping it with iptables off, again won't even ping it.

Seems like something is stopping it, even with firewalls off.
0
 
LVL 9

Expert Comment

by:absx
ID: 33645171
Ok,

Linux network administration is really not my area (I prefer to configure mine in GUI with Firestarter).
Maybe it'd be best to open another question on a different area for that and let this thread rest until fixed?

- Jarkko
0
 

Author Comment

by:JayRitchie
ID: 33645215
Sure, will give that a try, see what can be found out.

Thanks!
0
 

Author Closing Comment

by:JayRitchie
ID: 33655088
Whilest this was an IP issue, which i had to get investigated, there was still socket issues left over, so this expert helped me by giving an alternative which was CURL, a new language i'm now looking into.

Many thanks!
0

Featured Post

Supports up to 4K resolution!

The VS192 2-Port 4K DisplayPort Splitter is perfect for anyone who needs to send one source of DisplayPort high definition video to two or four DisplayPort displays. The VS192 can split and also expand DisplayPort audio/video signal on two or four DisplayPort monitors.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question