Android volley error 503 after 40 POST request

611 views Asked by At

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

There are 1 answers

3
mtricht On

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