put orders from android and receive from PHP
-
I have an Android application where customers can purchase and put orders Every customer can put order and I just have one `JSON` file in the `PHP` server to collect the orders from different customers The problem is if one customer puts his/her order, the `JSON` file shall be locked in order to prevent collision and if it is locked, how can another customer put order at the exact same time? To solve this issue, and for test, I decided to have a folder in the server where every customer (who is going to put an order) can put his unique ID there (uploading a text file with the name of the customer's ID) and I just read that folder to see who has put any order and then I delete the file which was uploaded by the customer indicating he/she has just put an order to be ready from another order from that customer (every customer creates a folder with his/her unique ID name to put detailed list of his/her orders and this is handled by PHP code) It works fine but does not seem to be a true manner from performance point of view Any suggestion?
-
I have an Android application where customers can purchase and put orders Every customer can put order and I just have one `JSON` file in the `PHP` server to collect the orders from different customers The problem is if one customer puts his/her order, the `JSON` file shall be locked in order to prevent collision and if it is locked, how can another customer put order at the exact same time? To solve this issue, and for test, I decided to have a folder in the server where every customer (who is going to put an order) can put his unique ID there (uploading a text file with the name of the customer's ID) and I just read that folder to see who has put any order and then I delete the file which was uploaded by the customer indicating he/she has just put an order to be ready from another order from that customer (every customer creates a folder with his/her unique ID name to put detailed list of his/her orders and this is handled by PHP code) It works fine but does not seem to be a true manner from performance point of view Any suggestion?
-
The PHP server should be able to handle multiple orders, just like any other web server.
-
The point is writing to the same file at the same time and as I searched it may create corruption
-
I have an Android application where customers can purchase and put orders Every customer can put order and I just have one `JSON` file in the `PHP` server to collect the orders from different customers The problem is if one customer puts his/her order, the `JSON` file shall be locked in order to prevent collision and if it is locked, how can another customer put order at the exact same time? To solve this issue, and for test, I decided to have a folder in the server where every customer (who is going to put an order) can put his unique ID there (uploading a text file with the name of the customer's ID) and I just read that folder to see who has put any order and then I delete the file which was uploaded by the customer indicating he/she has just put an order to be ready from another order from that customer (every customer creates a folder with his/her unique ID name to put detailed list of his/her orders and this is handled by PHP code) It works fine but does not seem to be a true manner from performance point of view Any suggestion?
AndroidVH wrote:
one `JSON` file in the `PHP` server to collect the orders from different customers
Unlike an ASP or PHP page, a JSON file does not "collect" anything. Based on what you've provided, unless you are doing something totally wrong, there should be no way for it to become locked. If multiple clients request the same JSON file, the web server will deliver the file to each client without issue.
AndroidVH wrote:
Any suggestion?
The whole "upload a file containing a customer number and/or order" approach seems way wrong to me. When you make contact with a web server, a one-on-one relationship has been established. When you interact with a web page (e.g., PHP file), you are doing so with your "copy" of it. If some other client is also interacting with that same page, again it's on their own "copy" of it. The web server keeps track of all those connections (up to some upper limit). Admittedly, I may be completely wrong on this. It borders on ecommerce which I have zero experience with. But what you are doing just seems kludgy and prone to error.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
AndroidVH wrote:
one `JSON` file in the `PHP` server to collect the orders from different customers
Unlike an ASP or PHP page, a JSON file does not "collect" anything. Based on what you've provided, unless you are doing something totally wrong, there should be no way for it to become locked. If multiple clients request the same JSON file, the web server will deliver the file to each client without issue.
AndroidVH wrote:
Any suggestion?
The whole "upload a file containing a customer number and/or order" approach seems way wrong to me. When you make contact with a web server, a one-on-one relationship has been established. When you interact with a web page (e.g., PHP file), you are doing so with your "copy" of it. If some other client is also interacting with that same page, again it's on their own "copy" of it. The web server keeps track of all those connections (up to some upper limit). Admittedly, I may be completely wrong on this. It borders on ecommerce which I have zero experience with. But what you are doing just seems kludgy and prone to error.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles