To give a brief idea of my current setup:
HTML form to collect the data for the Python Script
PHP inserts form data (POST) into input MySQL table
PHP exec s Python3.4 script.py row_id
Python collected the row ID using sys.argv[1] and runs the code and inserts the results into output MySQL table. When complete PHP displays a report (PHP waits for Python to complete, then I use header to go to the report URL).
The report pages are html with the blanks filled by PHP from the output MySQL table.
This worked fine for me testing and developing. The problem came when I released it into the wild for more general testing within the company - it is hosted on a VPS server and when the Server ran more than one instance of Python it ran like a dog (as we say in Scotland, because to say slow would be too easy).
Of course, the hosting company suggest upgrading, which we did and that doubled the capacity (from 1, sometimes 2 simultaneous runs, to 2 sometimes 3). I have now reached the conclusion that this method is not scalable, we are always going to hit some kind of limit.
So I have been looking at Amazon Web Services, but to do this requires a change in philosophy for the Python design - it must run all the time and have data fed in somehow (as far as I can see).
The Amazon suggestion is Flask or similar framework, but this would mean I then either have two web servers and have to do some kind of cross domain transfer of data, or else scrap what I have done - or at least heavily modify my PHP/HTML/JS that runs on the webserver so that it can be served by Flask and all be hosted by AWS.
Unless someone can suggest another way of communication that doesn't require a web framework, I have been considering either just polling the MySQL database at intervals and processing any new data, or else migrating the database to Postgre, which, I believe, allows Python code to run within the database structure and would enable me to trigger on insert (I believe the user defined triggers in MySQL only support C/C++).
Thanks for any suggestions or pointing out of things I am missing.
Blair
Further to infinigrove's suggestion Pyro4 works well for my use case, there is an excellent tutorial that provides an easy learning curve.
Selcuk's suggestion would probably also have worked, but I would still have been left with the problem of running the code on other servers in a distributed environment. Also if there is a choice between writing Python code and writing PHP I am afraid I take Python every time!
Related
Ive built an AngularJS application over the last several months that utilizes a MySQL database for its data. This data is fetched by Angular making calls to PHP and PHP returns JSON strings etc.
The issue is once this application is running inside node-webkit, none of the php works, so all of the content areas are empty. I assume (though the documentation on this issue is null and so i have no confirmation) this happens because Node-webkit is a client-side application framework and therefor wont run server-side languages like php. Is there a way to expand node webkit to run php and other server side languages?
I have done my best to find an answer to this question before posting, but documentation for this is nonexistent, and all of the information I have found about node-webkit talks about installing node on your server and installing npms for MySQL and having angular make calls to node. This defeats the purpose of the application entirely as it is designed so that the exe/deb/rpm/dmg can run and you can set up a database with any cloud database provider and be ready to go. Not ideal if you have to buy a vps just to run this one thing.
I have to assume this is possible in some way. i refuse to believe that everyone with an nw application hard codes all their data.
Thanks in advance
I know of four methods to accomplish this. Some of which you have preferred not to do but I am going to offer them in the hopes it helps you or someone else.
Look for an NPM that can do this for you. You should be able to do this functionality within node.js. - https://www.npmjs.com/search?q=mysql
You can host your PHP remotely. Using node-remote you can give this server the appropriate access to your NW.js project.
You can code a RESTful PHP application that your JavaScript can pass off information to.
You can use my boilerplate code to run PHP within a NW.js project. It however fires up an express.js web server internally to accomplish this. But the server is restricted to the machine and does not accept outside connections - https://github.com/baconface/php-webkit
1 and 4 both carry a risk in your case. Your project can be reversed engineered to reveal the source code and the connection information can be retrieved rather easy. So this should only be in an application on trusted machines and 2 and 3 are the ideal solutions.
I must developing an network monitor to monitoring several components using snmp. I save all received data in a round robin database.
I started to create an web based configuration center, that allows users to add devices to be monitored and access all the graphs (using rrdtool) of all devices.
I must run an daily, week, month and yearly update of the database.
My question is, how can i launch an script that executes an snmp command to fetch the data from the device and stores it on the databse and runs on background ? By background, i mean that it is a process that not depends if the user has logged in in the web configuration page or not.
I never did something in PHP, therefore i am asking you.
I hope you can help me out. Thank you in advance.
Best regard.
I have developed such a system a few years ago. We used Cacti, in combination with Nagios and Smokeping. Of course, if your needs are simpler, you could use cron scripts to fetch your data. But Cacti is definetely worth a look (as well as Nagios, but unlike Cacti, it's not specifically targetted at RRD files)
Note that none of these systems require PHP. They run standalone, as daemons. It's then pretty straightforward to write a web interface on top of that.
I maintain a PHP driven web application with Oracle backend. The app interacts with a number of third-party apps so information is managed with a combination of XML files, Microsoft Access databases and HTML forms. There are currently 80 tables with many BLOBs and a pretty good bunch of foreign key relationships. All procedures are carefully explained in a document that (of course) nobody ever reads. The customer was feeling uneasy about his data so he was given an estimate with some improvements that could be made (stuff like adding previews and confirmations in some operations).
Sadly, the customer misinterpreted one of the specs (a partial export to be written in 12 man-hours) and he's expecting a full backup and restore feature that would allow him to save and restore the complete database through a web browser without the DBA intervention.
Before having yet another argument with the client, I'd like to know whether I have any option to actually implement this feature in a timely manner, considering that it doesn't need any refinements (e.g., there is no need to select what to restore).
Production server is a Windows Server 2003 box running PHP/5.2.9. The Oracle server is a remote box running "Oracle9i Release 9.2.0.1.0 - 64bit Production".
(Please note I'm not a DBA so there may be well-known solutions I'm not aware of.)
Oracle is a monster. Once you've read this you'll realise that how you backup the system depends totally on how it has been configured. The short answer is to automate whatever manual process - invoke it as a long running process (since this is MSWindows, prefix the rman command with 'start') then use polling to detect when it finishes (e.g. wrap rman in a DOS batch file which logs start and end times).
I'd be hard pushed to think of a more difficult problem to provide a generic solution for than Oracle runing on top of MSWindows. The latter may be nice for users to click on buttons, but automating anything is a PITA.
Have fun :)
Finally, I had the chance of implementing full Oracle backup from PHP in a later project. I used the Oracle Data Pump command-line utilities, available since 10g. In short:
You define an Oracle directory to map a keyword to a physical directory and grant write permission to the app's Oracle user.
You run expdp with the appropriate arguments and get a complete dump in a single file.
To restore a backup, you run impdp.
It's also advisable to run commands with proc_open() rather than system() since you can bypass_shell if on Windows and have fine-grained control on the process.
As for this question, the pre-10g alternative is the "exp" / "imp" combo.
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.
I've been scouring Google to find out how I can make Flash bring at least two users together in an environment. What I've been trying to do is, for example: both users load http://example.com/myflashenvironment.html, and on that page is the same flashenv.swf file that they both see from two different computers. In the flashenv.swf there is a movieclip object that is draggable. I want to make it so if user 1 drags the movieclip then user 2 can see it being dragged, over the Internet in some kind of online type of deal. I've been trying to do it at runtime, like an online game.
I've been searching google and I've found things about sockets, but it's very hard to just jump right in when you are me. I've tried to figure out so far that I need a PHP file that creates a connects to my server with fsockopen, and then I need to create a socket? But then I don't know how to have user 1 write the (x, y) coordinates of the movieclip when he drags it and have user 2 automatically pick up those same coordinates.
And please believe me, I used this as a last resort to see if anyone knew what I am talking about. Google just isn't cutting it tonight.
It sounds to me like you need to read up on how to actually use sockets. Once you understand how they work, how you should structure your program should become very clear. You could serialize a small object with whatever you want the other user to see (like a coordinate change, for example).
But nevermind that, PHP is not what you want. PHP is not made for this sort of thing. What you need is some kind of standalone server - you would have to roll your own using C++ or Java, for example. PHP is made for short requests - you can't run it as a server. Yes, it does have sockets, but they're also made for quick one-shot connections. You need something that is always running, I'm assuming.
You should check out some of the flash multiuser servers that are already made if you don't want to roll your own. Red5 is a free one, and SmartFoxServer is a more fully featured server, but it is not free (they do have a free version, but it only supports a few concurrent users).
It is questionable (but not without precedence) to write and run a server in PHP.
The suggested Java based solution fits better for your needs.
If you are totally new to multi-user Flash, I recommend using SmartFox Server. It is very easy to use and there are many tutorials.
it is possible to create the socket server you want in php, but i don't really recommend it.
the difference to traditional php scripts is, you wouldn't run it like it's called over the browser, but a long-running (think infinite loop) cli-server-application (more like java)
simplified it works like this:
php: the script starts and listens for incoming request
flash: the flash app is started and connects to the server
php: the connection (from 2) is stored in an array
flash: now if the user moves his movieclip, the coordinates are sent to the script
php: data arrives (the coordinates from 4). now you loop through all connections and ...
... send the data to all the other movieclips
flash: if data (from 6) arrives, update the mc position accordingly
if the flash connection is terminated, remove it from the array
the problems:
- php is not really well suited for this
- you still have to learn about sockets. there are lots of tutorials on this topic, but most of them cover only single connections.
- depending on where you host it, your provider might not support long-running php-cli apps
No need to write your own server, use sockets or other complicated and time-consuming techniques.
Adobe has created the shared object class for exactly that purpose. You need to have a server running Flash Media Server (or equivalent) and use remote shared objects.