duanlvxi8652 2017-01-03 22:20
浏览 52

too long

I have a very simple program that sends POST to my server on godaddy using Volley. I created multiple requests in a loop. The code works fine for first few requests but randomly give error 503. There is specific pattern

My table only has 1 column i.e. userName

I have looked everywhere for almost 2 days to figure out why I am getting error 503. I understand this is because of server issue but I can't figure out what exactly is the issue.

Here is my code

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import java.util.HashMap;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
Button btnInsertData;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btnInsertData = (Button) findViewById(R.id.button);
    btnInsertData.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int counter = 1;
            while(counter<=20){
                insertData("user" + counter);
                counter++;
            }
        }
    });
}

private void insertData(final String data){
    String url = "http://...php";

    StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.i("Volley response", response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            try{
                Log.i("Volley Error", error.getMessage());
            }catch(Exception e){
                Log.i("Volley Error", "No error found");
            }
        }
    }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> map = new HashMap<String,String>();

            map.put("userName",data);

            return map;
        }
    };
    RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
    requestQueue.add(stringRequest).setShouldCache(false);

    Log.i("Status:", "Request created");
}
}

This is my php file

include_once './db_functions.php';
$db = new DB_Functions(); 

$user = $_POST["userName"];
$query = "INSERT INTO testTable (userName) VALUES ('".$user."')";
$result = mysql_query($query);

echo "status_new: ".$result." query: ".$query;

This is the error that I get

01-03 22:07:37.936 4434-8440/com.qallify.testapplicationvolley E/Volley:         [7441] BasicNetwork.performRequest: Unexpected response code 503 for http://....php
  • 写回答

1条回答 默认 最新

  • duanan6043 2017-01-03 22:28
    关注

    If you are on godaddy's shared hosting, you are most likely hitting the resource limits described here: https://nl.godaddy.com/help/resource-limits-12001

    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗