PHP file for "Web Service" queries between IOS App and Database - php

I am developing an IOS application that communicates with a database with "web service" requests.
To do this, I write the many SQL queries in a single PHP file that serves as a "bridge" between the application and the database.
My question is the following :
Do I have to make several PHP files (which grouped feature-ordered templates) or can I write all PHP queries in one file (which is so large)?
In addition, some queries allow me to upload images to the server with a rather long transfer time. If I keep these queries in the same PHP file, will it "block" or "slow down" access to this file for other users? Should I make PHP files apart for upload?
For the moment, I develop this application locally and I do not see any problem with a single PHP file. But I have a doubt when putting into production on a real server.
Thank you.

You can make serveral page for each web service or you can do it only in one page. But it dependes upon your application requirements. If it is a huge application then, it would be better to use different webservice for every api call.
The main demerit of single page web service is, if there is a problem in your 1 function then the application will not work at all and you might be think where is the issue.
If you used different web service for different functionality then it will not work on that page only and it will not affect other pages of your application.

Related

PHP long-polling with .txt-File instead of a MySQL Database

I want to implement a simple long polling system in PHP. A simple Szenario:
The Project is based on two websites. Website A and Website
B. There are two Users. One on Website A (UserA) and one on
Website B (UserB). On the Website A is a Button. If UserA push the
Button, the color of Website B change instantly.
Of course i can do this with a MySQL Database, but this seems way to big, because i just want to transfer one Bit.
Are there any other oppurtinitys to store one Bit on the Server an have acces from all PHP Pages, which are hosted on the Server?
I thought i could use a simple .txt file, but i am not shure if the Server Crushes if two diffrent Websites want to access to the same file. Is this a problem?
Or have you any other Ideas how to resolve it?
I would not recommend using a text file, since I/O operations is pretty slow compared to other methods.
You have to read the file on every page load/refresh or even worse, with an ajax request to do it instant. I think I would recommend something like Redis / Memcached and make some sort of ajax call to read from that (if you want it to be instant).
If you don't have access to the server, to install that kind of software, I would use a MySQL database.
Hope it helps

Objective-c upload to database using script

I am about to develop an application for the iOS devices, that will need to store information in a database on the web. For previous projects, i would just have PHP scripts, and my application would run those scripts and passing in the stuff to upload as _GET parameters, like this:
http://example.com?name=George&contents=iWillBePutIntoDB
However, this is not possible for my next project, as it will contain rather large amount of text, and i could exceed the maximum allowed length of a URL.
So, how do i go about doing this? I cannot access the MySQL database directly from my app, since my shared hosting provider doesn't allow it due to security reasons. So i can only access it using PHP scripts that are stored directly on the server.
In short: How do i upload large amount of text to a MySQL database that doesn't allow access from anywhere except files on the server itself (PHP scripts)?
Thanks everyone!
One obvious way would be using POST, instead of using GET.
But take it into your considerations that post is not without its limits.

Suggestion for upgrading VB6 app w/ good printing support

I wrote an application on VB6/Access for a retail shop almost 8 yrs ago. They are still using it, and now they are asking for changes/upgrade and want to access from multiple locations + multiple machine per location. Earlier it was just one machine per location.
All location is going to run the same application except only the Inventory and customers are different along with app settings. Inventory should be able to move to different location.
I lost touch with VB & Access, also I would like to rewrite the app with open source tools.
I'm a web developer PHP/MySQL and can do html5 if necessary. I believe I can rewrite all the functionalities with PHP/MySQL but I am not confident in printing.
The main requirement of the app is, it should print as fast as it can, should support several custom paper sizes.
Also the database should work distributed environment, all location should be able to work independently as well as able to sync updates when connected.
What is the best thing I can do in
this situation?
Would you recommend to create webapp, and do any desktop
client only for printing. i.e VB in
windows or shell script if linux? or
any alternative?
Any recommended workflow/links for Database setup/mirroring?
Modify the existing VB application to run with required MySQL architecture?
Sorry to violate one question per post rule, but I don't know how to split it.
Lets start with printing.
You could do a print CSS file. But its not very precise. That would get printed from the client browser.
Generate a PDF. With that you could print from the server or from the client. Server would be a faster option. Although multiple printers could get complicated.
Database sync:
I would treat the central database as a separate app and devise rules for each location to sync to the central location. You may not need to share all data, and just replicating the data you get into complex replication rules.

access + mysql converting to webplatform = (php + asp.net + mysql)?

i have a database that is written in access. the access mdb file connects via ODBC to a local mysql database. i have a bunch of sql and vba code in the access file. i dont expect the database to surpass 100mb. currently it is around 10mb. i will need to have multiple user access. (no more than 10 users at a time)
i need to convert this database from being a local one to a web server, and i need to make a web interface for it.
how do i get the current local instance of mysql database to run off a webserver? i am currently running it off wampserver 2.0. i dont have experience putting a database on a webserver.
i have an OK vb.net background. i have never done any web applications. here's a picture of the access form that i may need to replicate to work off a website:
alt text http://img42.imageshack.us/img42/1025/83882488.jpg
which platform should i use as the front end to this thing?
would it be possible to just run this access file off a webserver instead of programming a new front end for it? is that not a smart idea?
thank you for your help!
If your webserver has TCP connectivity to your existing database server, and its hosted in a suitable place (eg, don't have your webserver in a datacenter connecting to a database server on your office DSL connection), then no move is required.
If you do need to move it, it's as easy as creating a backup/dump, and restoring it elsewhere.
As far as the frontend, there are MANY technologies that will do what you need (ASP.NET, PHP, Python, Ruby, Perl, Java being the most popular ones, not necessarily in that order).
Use something you are comfortable with, or that you are interested in learning (provided you have the time to do so)
Use something that runs properly on your target webserver. Really, ASP.NET is the only one that has any major issue here, as it's limited to Windows.
Access itself has no direct web-accessible version. A Google search finds some apps that claim to convert Access forms to web-based, but I will not link to any because I don't know how well they work. I'm certainly leary of anything like that, because web apps are a different breed from Windows apps. If you are going to go that route, be sure they actually generate HTML output; make sane, clean source; and offer a free trial so you can verify it actually works.
Really though, a form like that is reasonably easy to reproduce with some basic knowledge of server-side programming and some HTML.
I don't have any experience migrating access to a web-based interface, although I have heard of people going straight from access to a web page. MySql is exceptionally easy to migrate. MySQL.com has a program called mysqldump that comes with the standard install of MySQL that allows you to export your database straight to a text file that can be used then with mysqldump to import it on another server. I don't believe the WAMP server comes with the command line tools although they can be downloaded from mysql.com. However, if it has phpMyAdmin, then there is also an export feature with that as well that will generate a .sql file that can be imported to the webserver using phpMyAdmin. One thing to keep in mind though is that I have had very little success mixing and matching these methods: ie, I've never been able to get a mysqldump-created file to work with phpMyAdmin and vice versa.
Good luck!
The link will help you to export and import mySQL database
May be on Windows web server there is an opportunity to run Access files, you can check, but any way if you have some programming skills, I would say that it is not difficult to crate a php script which will query your database info and will edit.
Migrating an Access application to the web is quite difficult, because you can't translate an Access form 1:1 into a web page. Web apps are stateless, whereas Access is built around the concept of bound controls and bound datasets.
Secondly, it is impossible to easily replicate an Access subform.
Third, you lose tons of events that Access forms and controls are built around.
In general, a web page that performs the same task as an Access form will bear little or no resemblance to the Access form, simply because the methods for accomplishing the same tasks and the UI widgets available to you are so completely different.
One thing to consider is whether your users need a web application or if they just need to use your existing Access application over the Internet. If the latter is the case, Windows Terminal Server/Citrix can do the job for a lot less money, since there's no conversion needed. You do need to provision a Windows Terminal Server, set up a VPN and purchase CALs for the users, but the costs of those are going to be much less than the cost of rebuilding the app for web deployment.
It may not be an appropriate solution, but it's one that you should consider, I think.

Communication between PHP and application

I'm playing with an embedded Linux device and looking for a way to get my application code to communicate with a web interface. I need to show some status information from the application on the devices web interface and also would like to have a way to inform the application of any user actions like uploaded files etc. PHP-seems to be a good way to make the interface, but the communication part is harder. I have found the following options, but not sure which would be the easiest and most convenient to use.
Sockets. Have to enable sockets for the PHP first to try this. Don't know if enabling will take much more space.
Database. Seems like an overkill solution.
Shared file. Seems like a lot of work.
Named pipes. Tried this with some success, but not sure if there will be problems with for example on simultaneous page loads. Maybe sockets are easier?
What would be the best way to go? Is there something I'm totally missing? How is this done in those numerous commercial Linux based network switches?
I recently did something very similar using sockets, and it worked really well. I had a Java application that communicates with the device, which listened on a server socket, and the PHP application was the client.
So in your case, the PHP client would initialize the connection, and then the server can reply with the status of the device.
There's plenty of tutorials on how to do client/server socket communication with most languages, so it shouldn't take too long to figure out.
What kind of device is it?
If you work with something like a shared file, how will the device be updated?
How will named pipes run into concurrency problems that sockets will avoid?
In terms of communication from the device to PHP, a file seems perfect. PHP can use something basic like file_get_contents(), the device can just write to the file. If you're worried about the moment in time the file is updated to a quick length check.
In terms of PHP informing the device of what to do, I'm also leaning towards files. Have the device watch a directory, and have the script create a file there with something like file_put_contents($path . uniqid(), $command); That way should two scripts run at the exact sime time, you simply have two files for the device to work with.
Embedded linux boxes for routing with web interface don't use PHP. They use CGI and have shell scripts deliver the web page.
For getting information from the application to the web interface, the Shared file option seems most reasonable to me. The application can just write information into the file which is read by PHP.
The other way round it looks not so good at first. PHP supports locking of files, but it most probably doesn't work on a system level. Perhaps one solution is that in fact every PHP script which has information for the application creates it own file (with a unique id filename, e.g. based on timestamp + random value). The application could watch a designated directory for these files to pop-up. After processing them, it could just delete them. For that, the application only needs write permission on the directory (so file ownership is not an issue).
If possible, use shell scripts.
I did something similar, i wrote a video surveillance application. The video part is handled by motion (a great FOSS package). The application is a turn-key solution on standardized hardware, used to monitor slot-machine casinos. It serves as a kiosk system locally and is accessible via internet. I wrote all UI code in PHP, the local display is a tightly locked down KDE desktop with a full screen browser defaulting to localhost. I used shell scripts to interact with motion and the OS.
On a second thought:
If you can use self-compiled applications on the device: Write a simple program that returns the value you want and use PHP's exec() or passthru() or system().

Categories