What are the minimum necessary settings for handling 100000 concurrent request for a php mysql web application
Recently we had developed a registration portal using php and mysql on a single server based on xeon processor. Unfortunately this server couldn't handle concurrent requests of more than a few thousands. i have heard about load balancing , clustering and high availability. How to achieve the above scenario using aws or google cloud . what are the necessary services needs to purchase for the same
See also questions close to this topic
-
I would like to make a panel to manage reviews
I made a website where I have a page for reviews, where users can freely write, but I would like the requests to arrive in a panel before they are published where I can reject or approve the reviews. How should I do?
I would simply like to make sure that not all posts are approved.
CODE:
function time_elapsed_string($datetime, $full = false) { $now = new DateTime; $ago = new DateTime($datetime); $diff = $now->diff($ago); $diff->w = floor($diff->d / 7); $diff->d -= $diff->w * 7; $string = array('y' => 'year', 'm' => 'month', 'w' => 'week', 'd' => 'day', 'h' => 'hour', 'i' => 'minute', 's' => 'second'); foreach ($string as $k => &$v) { if ($diff->$k) { $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : ''); } else { unset($string[$k]); } } if (!$full) $string = array_slice($string, 0, 1); return $string ? implode(', ', $string) . ' ago' : 'just now'; } if (isset($_GET['page_id'])) { if (isset($_POST['name'], $_POST['rating'], $_POST['content'])) { $stmt = $pdo->prepare('INSERT INTO reviews (page_id, name, content, rating, submit_date) VALUES (?,?,?,?,NOW())'); $stmt->execute([$_GET['page_id'], $_POST['name'], $_POST['content'], $_POST['rating']]); exit('Your review has been submitted!'); } $stmt = $pdo->prepare('SELECT * FROM reviews WHERE page_id = ? ORDER BY submit_date DESC'); $stmt->execute([$_GET['page_id']]); $reviews = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt = $pdo->prepare('SELECT AVG(rating) AS overall_rating, COUNT(*) AS total_reviews FROM reviews WHERE page_id = ?'); $stmt->execute([$_GET['page_id']]); $reviews_info = $stmt->fetch(PDO::FETCH_ASSOC); } else { exit('Please provide the page ID.'); } ?> <div class="overall_rating"> <span class="num"><?=number_format($reviews_info['overall_rating'], 1)?></span> <span class="stars"><?=str_repeat('★', round($reviews_info['overall_rating']))?></span> <span class="total"><?=$reviews_info['total_reviews']?> reviews</span> </div> <a href="#" class="write_review_btn">Write Review</a> <div class="write_review"> <form> <input name="name" type="text" placeholder="Your Name" required> <input name="rating" type="number" min="1" max="5" placeholder="Rating (1-5)" required> <textarea name="content" placeholder="Write your review here..." required></textarea> <button type="submit">Submit Review</button> </form> </div> <?php foreach ($reviews as $review): ?> <div class="review"> <h3 class="name"><?=htmlspecialchars($review['name'], ENT_QUOTES)?></h3> <div> <span class="rating"><?=str_repeat('★', $review['rating'])?></span> <span class="date"><?=time_elapsed_string($review['submit_date'])?></span> </div> <p class="content"><?=htmlspecialchars($review['content'], ENT_QUOTES)?></p> </div> <?php endforeach ?>
-
SELECT from MySQL table - Move down every rows of single column by 1 row
I have MySQL table. I use this to display data on my website:
$daily = "SELECT id, weight, sys FROM scale ORDER BY id DESC LIMIT 24"; $result_daily = $conn->query($daily); <table> while($row = $result_daily->fetch_assoc()) { echo "<tr><<td>". $row["id"]. "</td><td>" . $row["weight"] . "</td><td>". $row["sys"]. "</td></tr>"; }echo "</table>";}?>
This will show data like this:
id. weight sys | 5. | 32.5 | 15 | | 4. | 31.5 | 14 | | 3. | 34.5 | 17 | | 2. | 31.5 | 15 | | 1. | 30.0 | 16 |
I would like to move down every rows of sys column by 1 row. Like this:
id. weight sys | 5. | 32.5 | | | 4. | 31.5 | 15 | | 3. | 34.5 | 14 | | 2. | 31.5 | 17 | | 1. | 30.0 | 15 |
-
How to get gross revenue data from woocommerce by product ID?
I'm trying to get woocommerce total revenues for each of my products. I'm using this in a custom plugin, which will eventually email the data to colleagues. However, I can't manage to get that data. Which seems banal, I know, but I'm not good at OOP and Woo is all about OOP... sigh.
I can actually kind of get the result by pushing an SQL query into my loop, but I'd really prefer to use the wc classes to do this so it's more "futureproof".
Here's what I have so far:
// Use get_posts to grab my product IDs function grab_product_ids() { $product_posts = get_posts( array( 'post_type' => 'product', 'numberposts' => -1, 'post_status' => 'publish', 'fields' => 'ids', ) ); // Push resulting IDs into a loop, which has to return total revenues... foreach ( $product_posts as $product ) { $sales = get_product_gross_revenue( $product ); echo $product . " (" . get_the_title($product) .") " . "Total sales: " . $sales . "</br>"; } } function get_product_gross_revenue() { // and here I'm stuck... }
I've tried two approaches so far for that last function:
1st approach - Gets total values for ALL orders in the shop. I want to limit it to each product. AND I also suspect that this is a really heavy query to call.
//Approach #1 function get_product_gross_revenue() { $query = new WC_Order_Query( array( 'limit' => -1, //something about prod ID should go here?? ) ); $earnings = 0; $orders = $query->get_orders(); foreach( $orders as $order ) { $earnings = $earnings + $order->total; } } }
2nd approach, using Get WooCommerce Product total sales amount answer code. It works (though I haven't checked accuracy of return values). However, it just feels wrong doing a direct SQL query for this when I'm sure Woo must have something built in.
Any suggestions much appreciated.
-
Select with alias in CI 4
I have a problem with a query in my CI4 software. I've seen that query was really slow even if the table contains only 9k records. With SHOW FULL PROCESS LIST; I get the query and I've noticed something strange with alias:
SELECT `mov`.* FROM (`Movements`, `Movements` as `mov`) JOIN `Articles` as `art` ON `art`.`id` = `mov`.`articleId` GROUP BY `mov`.`id` ORDER BY `id` desc LIMIT 20
The table name was repeated and this causes a huge slowing of the table.
That's my CI4 code which create this query
$this->select('mov.*'); $this->from('Movements as mov'); $this->join('Articles as art', 'art.id = mov.articleId'); $this->groupBy("mov.id"); $this->orderBy("id"); $this->limit(20);
-
How to set Markes on MapFragment with Server response Lat/Lng?
in my application i send lat/lng values to a server and filter my database with the location values included to get results in a certain Radius. In my application i display the result in a recyclerview. Everything works perfect and i got the result and could display it also in a recyclerview.
I got the response in a Activity and display the result in a fragment with recyclerview. How to use the response lat lng in a new MapFragment? How could i pass the Data to my Map Fragment and add it to a Marker. Activity where i send the values to server and get the response back
public void onLocationChanged(Location location) { double latitude = location.getLatitude(); double longitude = location.getLongitude(); getAddressString(latitude, longitude); final String lat1 = String.valueOf(latitude); final String lng1 = String.valueOf(longitude); Log.d(TAG, "onLocationChanged: postition" + " latitude " + latitude + " longitude" + longitude); JsonObject object; class AddCoord extends AsyncTask<Void, Void, String> { public String res; @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected void onPostExecute(String res) { super.onPostExecute(res); RecyclerView recyclerView= findViewById(R.id.recyclerview); try { JSONArray responsearray = new JSONArray(res); ArrayList<Data> DATA = new ArrayList<>(); //Populate the EmployeeDetails list from response for (int i = 0; i<responsearray.length();i++){ JSONObject event = responsearray.getJSONObject(i); Data events = new Data(); events.setId(event.getInt("ID")); events.setEvent1(event.getString("Event1")); events.setEvent2(event.getString("Event2")); events.setEvent2(event.getString("Event2")); events.setG(event.getString("G")); events.setDA(event.getString("Da")); events.setADRESS(event.getString("City")); events.setStartTIME(event.getString("StartTime")); events.setEndTIME(event.getString("EndTime")); events.setP(event.getString("P")); events.setLat(event.getString("latitude")); events.setLng(event.getString("longitude")); DATA.add(events); // <<<<<< Here is the Change } //Create an adapter with the EmployeeDetails List and set it to the LstView RecyclerAdapter recyclerAdapter = new RecyclerAdapter(getParent(),DATA); recyclerView.setAdapter(recyclerAdapter); } catch (JSONException e) { e.printStackTrace(); } // System.out.println(getResponse); } @Override protected String doInBackground(Void... v) { HashMap<String, String> params = new HashMap<>(); params.put(Config.KEY_EMP_LAT, lat1); params.put(Config.KEY_EMP_LNG, lng1); RequestHandler rh = new RequestHandler(); String res = rh.sendPostRequest(Config.URL_ADD, params); Log.d(TAG, "doInBackground: "+ params); Log.d(TAG, "doInBackground: SENDED!"); Log.d(TAG, "doInBackground: "+ res); return res; } } AddCoord ac = new AddCoord(); ac.execute(); }
Map Fragment
public class Map_Fragment extends Fragment implements OnMapReadyCallback{ /**Stuff*/ SupportMapFragment mapFragment; private static ArrayList<Data> DATA; private static final String TAG = "MapFragment"; private static String lat; private static String lng; /**On Create (Whole stuff to run when fragment is called)*/ @Override public void onCreate(Bundle savedInstanceState) { Log.d(TAG, "getStart"); super.onCreate(savedInstanceState); } /**Create View for Fragment*/ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d(TAG, "getStart"); View v = inflater.inflate(R.layout.fragment_map_, container, false); mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map); if (mapFragment == null) { FragmentManager fm = getFragmentManager(); assert fm != null; FragmentTransaction ft = fm.beginTransaction(); mapFragment = SupportMapFragment.newInstance(); ft.replace(R.id.map, mapFragment).commit(); } mapFragment.getMapAsync(this); // Inflate the layout for this fragment return v; } /**Whole stuff to run when Map is called*/ @Override public void onMapReady(GoogleMap mMap) { assert mMap != null; Log.d(TAG, "getStart"); if (ActivityCompat.checkSelfPermission(Objects.requireNonNull(getContext()), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } /** get User Location*/ LocationManager lm = (LocationManager) Objects.requireNonNull(getActivity()).getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); assert location != null; double longitude = location.getLongitude(); double latitude = location.getLatitude(); LatLng yourLocation = new LatLng(latitude, longitude); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(yourLocation, 10)); CircleOptions circleOptions = new CircleOptions() .center(yourLocation) //set center .radius(20000) //set radius in meters .strokeColor(R.color.colorbackround) .strokeWidth(3); mMap.addCircle(circleOptions); } }
-
RESTful API design and cookies
I have a API which sends an authentication token as a cookie based on the
/signin
route (which is then also stored in a map in the server code).Is the API still considered restful and stateless if such cookies are used and information is stored on the server about these cookies?
Furthermore, when designing a route with the endpoint
/foo
, I can either use/:userId/foo
to fetch a user's data or just/foo
, customising my results based on the authentication token which the request is carrying to access the user data. Which approach is more typically used? -
How to install tomcat server on windows machine
How to install tomcat server on windows machine when we don't have admin rights. I also need to know
- which files to download
- the cmd command to install
- How to set the jre in this case.
- how to run
-
How to integrate AWS api gateway with EKS cluster to access the microservices deployed on cluster IP using ELB
I have created EKS cluster in that cluster created 2 nodes & deployed few microservices on cluster IP. As cluster IP is only internally accessible so wanted to configure it with AWS API gateway using ELB.
-
Create new instances in AWS Elastic Beanstalk programmatically
I am new to AWS Elastic Beanstalk and I am trying to understand it by reading the documentation and developing from it. As my reading was growing, I came up with the following question: is it possible to scale up or down an application by its source code? For instance, if my application reaches some threshold, it must scale up.
I have researched about it but could not find any code that does that and the only way that I found to scale an application is to increase or decrease its instances by AWS Elastic Beanstalk console.
Can anyone help me to confirm if there is a way to do it programmatically, or the only way to scale up and down is by doing it by the console?
-
AWS ALB Target Group shows unhealthy instances in a custom VPC
I am trying to achieve the following network topology. I want the EC2 instances in private subnets to receive http traffic on port 80 from application load balancer.
For that
I have launched EC2 instances in both the private subnets each. Also, installed apache web server with index.html using the following user data script.
#!/bin/bash yum update -y yum install -y httpd.x86_64 systemctl start httpd.service systemctl enable httpd.service echo “Hello World from $(hostname -f)” > /var/www/html/index.html
Next, I created ALB in the public subnets. Also, registered EC2 instances with a Target Group while creating the ALB. But health checks for the registered EC2 instances always fail. Please find the image below.
I have double checked security groups for EC2 instances and ALB. Both looks fine to me. Could anyone please let me know what am I missing here ?
thanks
-
Can a database be added to an HA group online?
Edited
I created a new database on my HA server and I need to add it the to availability group. It's a new database and doesn't have anything in it. The HA group contains multiple critical databases running in it.
Can I add the new database to the HA group without affecting the currently running databases? Will it bring down the HA during the operation?
Didn't find that info on msdn. Thanks for the help
-
Replicated container of Certificate Authority (CA) server is not working
I am trying to Maintain the High Availability (HA) of the Certificate Authority (CA) server (Without using the Container orchestration Technique like K8). To achieve that, I used the YAML anchor and merge syntax. Both containers run and listen to the server port. The Problem here arises is, Only one server works as expected as previous as a normal, and another replicated using merge and anchor is not working. It throws an error while sending a request to the replicated server using SDK. I performed enrollAdmin operation using enrollAdmin.js provided by fabcar (sample provided by hyperledger fabric). The error code is as below :
gopal@gopal:~/Dappdev/first/fabric-samples/fabcar/javascript$ node enrollAdmin.js Wallet path: /home/gopal/Dappdev/first/fabric-samples/fabcar/javascript/wallet Enroll the admin user, and import the new identity into the wallet 2021-01-12T08:42:03.572Z - error: [FabricCAClientService.js]: Failed to enroll admin, error:%o message=Calling enrollment endpoint failed with error [Error: write EPROTO 139961596319552:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332: ], stack=Error: Calling enrollment endpoint failed with error [Error: write EPROTO 139961596319552:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332: ] at ClientRequest.request.on (/home/gopal/Dappdev/first/fabric-samples/fabcar/javascript/node_modules/fabric-ca-client/lib/FabricCAClient.js:487:12) at ClientRequest.emit (events.js:198:13) at TLSSocket.socketErrorListener (_http_client.js:401:9) at TLSSocket.emit (events.js:198:13) at errorOrDestroy (internal/streams/destroy.js:107:12) at onwriteError (_stream_writable.js:436:5) at onwrite (_stream_writable.js:461:5) at _destroy (internal/streams/destroy.js:49:7) at TLSSocket.Socket._destroy (net.js:614:3) at TLSSocket.destroy (internal/streams/destroy.js:37:8) Failed to enroll admin user "admin": Error: Calling enrollment endpoint failed with error [Error: write EPROTO 139961596319552:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332: ] gopal@gopal:~/Dappdev/first/fabric-samples/fabcar/javascript$
Additionally, to explain more, I am adding CA configuration file as below.
version: '2' networks: byfn: services: ca0: &name-me image: hyperledger/fabric-ca:$IMAGE_TAG environment: - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server - FABRIC_CA_SERVER_CA_NAME=ca-org1 - FABRIC_CA_SERVER_TLS_ENABLED=true - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/key.pem - FABRIC_CA_SERVER_PORT=7054 ports: - "7054:7054" command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/key.pem -b admin:adminpw -d' volumes: - ./crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config container_name: ca_server01 networks: - byfn # Replicated CA ca01: <<: *name-me # <- this is a merge (<<) with an alias (*name-me) # keys below merge notation override those that declared under anchor # so this: ports: - "8054:8054" container_name: ca_server02 environment: - FABRIC_CA_SERVER_PORT=8054
Further more, to confirm the configuration, I have added a connection profile for this CA.
"certificateAuthorities": { "ca.org1.example.com": { "url": "https://localhost:8054", "caName": "ca-org1", "tlsCACerts": { "pem": "-----BEGIN CERTIFICATE-----\nMIICUDCCAfegAwIBAgIQWmpv94Te6dBKBjMEJrZ/RDAKBggqhkjOPQQDAjBzMQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu\nb3JnMS5leGFtcGxlLmNvbTAeFw0yMDEyMDQwODI1MDBaFw0zMDEyMDIwODI1MDBa\nMHMxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T\nYW4gRnJhbmNpc2NvMRkwFwYDVQQKExBvcmcxLmV4YW1wbGUuY29tMRwwGgYDVQQD\nExNjYS5vcmcxLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\nvhAwa7BeZTdV+Sevx0LEg+dptt1GIaQpukOhiEGmstF7Re8okIQXhQw/WjTVWlv8\nGccHPcoUuVe6nBklpHEL/qNtMGswDgYDVR0PAQH/BAQDAgGmMB0GA1UdJQQWMBQG\nCCsGAQUFBwMCBggrBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1UdDgQiBCBJ\n/ICyRsXWQVxtcPI0+8+ZtAYHGXb0z4VBd5yvvmv64zAKBggqhkjOPQQDAgNHADBE\nAiBYadQuHePis5gPkEoLR3yVaYzEADap31XcSg9P1L6akAIgMoxWuq58zpQrIY0X\nh4zC6aHdSt2u4hJtXLB+8JNzVy8=\n-----END CERTIFICATE-----\n" }, "httpOptions": { "verify": false } }
How to solve this issue of replicated docker container not working for CA server replication?
-
Data streaming API- High availability
In my architecture on AWS, I have a service running on an EC2 instance which calls Twitter streaming API for data ingestion i.e. ingestion of real-time tweets. I call this service TwitterClient.
Twitter API uses a kindof long polling over HTTP protocol to deliver streaming data. The documentation says- a single connection is opened between your app (in my case, TwitterClient) and the API, with new tweets being sent through that connection.
TwitterClient then passes the real-time tweets to the backend (using Kinesis Data streams) for processing.
The problem I am facing is- running multiple EC2 instances in parallel will result in duplicate tweets being ingested and each tweet will be processed several times. However, only one instance of EC2 becomes a single point of failure.
I cannot afford downtime as I can't miss a single tweet.
What should I do to ensure high availability?
Edit: Added a brief description of how Twitter API delivers streaming data