{"action":"created","issue":{"url":"https://api.github.com/repos/mgp25/Chat-API/issues/738","labels_url":"https://api.github.com/repos/mgp25/Chat-API/issues/738/labels{/name}","comments_url":"https://api.github.com/repos/mgp25/Chat-API/issues/738/comments","events_url":"https://api.github.com/repos/mgp25/Chat-API/issues/738/events","html_url":"https://github.com/mgp25/Chat-API/issues/738","id":78496500,"number":738,"title":"400 Bad Request","user":{"login":"Raghava525","id":12528568,"avatar_url":"https://avatars.githubusercontent.com/u/12528568?v=3","gravatar_id":"","url":"https://api.github.com/users/Raghava525","html_url":"https://github.com/Raghava525","followers_url":"https://api.github.com/users/Raghava525/followers","following_url":"https://api.github.com/users/Raghava525/following{/other_user}","gists_url":"https://api.github.com/users/Raghava525/gists{/gist_id}","starred_url":"https://api.github.com/users/Raghava525/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Raghava525/subscriptions","organizations_url":"https://api.github.com/users/Raghava525/orgs","repos_url":"https://api.github.com/users/Raghava525/repos","events_url":"https://api.github.com/users/Raghava525/events{/privacy}","received_events_url":"https://api.github.com/users/Raghava525/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-05-20T12:02:17Z","updated_at":"2015-05-20T12:59:43Z","closed_at":null,"body":"ml>\r\n400 Bad Request\r\nnginx/1.4.2\r\nErrors :\r\nSocket :Resource id #18\r\nheader length : 3\r\ntreeLength :813172\r\n\r\n\r\n\r\nPlease check the code.\r\nI am getting 400 bad request repeatedly .\r\n\r\n public function readStanza()\r\n    {\r\n        $buff = '';\r\n        if ($this->socket != null) {\r\n            $header = @socket_read($this->socket, 3);//read stanza header\r\n            if ($header === false) {\r\n                $error = \"socket EOF, closing socket...\";\r\n                socket_close($this->socket);\r\n                $this->socket = null;\r\n                $this->eventManager()->fire(\"onClose\",\r\n                    array(\r\n                        $this->phoneNumber,\r\n                        $error\r\n                    )\r\n                );\r\n            }\r\n\r\n            if (strlen($header) == 0) {\r\n                //no data received\r\n                return;\r\n            }\r\n            if (strlen($header) != 3) {\r\n                throw new ConnectionException(\"Failed to read stanza header\");\r\n            }\r\n            $treeLength = (ord($header[0]) & 0x0F) << 16;\r\n            $treeLength |= ord($header[1]) << 8;\r\n            $treeLength |= ord($header[2]) << 0;\r\n\r\n            //read full length\r\n            $buff = socket_read($this->socket, $treeLength);\r\n\t\t\techo $buff;\r\n\t\t\techo \"Errors : <br>\";\r\n\t\t\techo \"Socket :\".$this->socket.'<br>';\r\n\t\t\techo \"header length : \".strlen($header).\"<br>\";\r\n\t\t\t\r\n\t\t\techo \"treeLength :\".$treeLength.\"<br>\";\r\n\t\t\texit;\r\n\t\t\t\r\n            //$trlen = $treeLength;\r\n            $len = strlen($buff);\r\n            //$prev = 0;\r\n            while (strlen($buff) < $treeLength) {\r\n                $toRead = $treeLength - strlen($buff);\r\n                $buff .= socket_read($this->socket, $toRead);\r\n                if ($len == strlen($buff)) {\r\n                    //no new data read, fuck it\r\n                    break;\r\n                }\r\n                $len = strlen($buff);\r\n            }\r\n\r\n            if (strlen($buff) != $treeLength) {\r\n                throw new ConnectionException(\"Tree length did not match received length (buff = \" . strlen($buff) . \" & treeLength = $treeLength)\");\r\n            }\r\n            $buff = $header . $buff;\r\n        } else {\r\n            $this->eventManager()->fire(\"onDisconnect\",\r\n                array(\r\n                    $this->phoneNumber,\r\n                    $this->socket\r\n                ));\r\n        }\r\n\r\n        return $buff;\r\n    }\r\n\r\n\r\nCan you please tell me mistake in this code ?"},"comment":{"url":"https://api.github.com/repos/mgp25/Chat-API/issues/comments/103875784","html_url":"https://github.com/mgp25/Chat-API/issues/738#issuecomment-103875784","issue_url":"https://api.github.com/repos/mgp25/Chat-API/issues/738","id":103875784,"user":{"login":"0xTryCatch","id":5276448,"avatar_url":"https://avatars.githubusercontent.com/u/5276448?v=3","gravatar_id":"","url":"https://api.github.com/users/0xTryCatch","html_url":"https://github.com/0xTryCatch","followers_url":"https://api.github.com/users/0xTryCatch/followers","following_url":"https://api.github.com/users/0xTryCatch/following{/other_user}","gists_url":"https://api.github.com/users/0xTryCatch/gists{/gist_id}","starred_url":"https://api.github.com/users/0xTryCatch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/0xTryCatch/subscriptions","organizations_url":"https://api.github.com/users/0xTryCatch/orgs","repos_url":"https://api.github.com/users/0xTryCatch/repos","events_url":"https://api.github.com/users/0xTryCatch/events{/privacy}","received_events_url":"https://api.github.com/users/0xTryCatch/received_events","type":"User","site_admin":false},"created_at":"2015-05-20T12:59:43Z","updated_at":"2015-05-20T12:59:43Z","body":"Are you having many groups?"}}