Need an advice on text-processing flow - php

I've been a research programmer (MATLAB) for most of my programming career, writing things for only myself that can be run on my own computer. Now, I'd like to be able to have people submit a comma-delimited text file and get processed text files in return without having to use my computer directly (only 1 MATLAB installment).
I'm thinking perhaps this can be done on my web server (XAMPP) over LAN and some programming language script that can be run on my server. This is what I'm thinking:
have people create comma-delimited text files.
have them go to a site I created on my localhost and submit it via a webpage forum.
have the uploaded file processed in PHP (small files, < 100KB). This involves looking up a MySQL database as well.
have people download the processed files somehow.
Is this a sound system? By "sound" I mean, if you, the expert, wanted to set up this system, would this be the steps and tools you would use? I've been learning PHP lately, and it seems like I could do this using PHP, but I'm not sure if this is the right tool for the task. The whole thing seems ... a bit on-the-fly, as in you upload the file, and things are done in PHP memory (from what I've read) instead of the file being stored on my server and the server running a script using that file (is there a difference?!). I would be greatly thankful if you guys could chime in and give me some pointers on how to do this properly (general ideas, not asking for codes).

PHP is most definitely a good tool for something like this. As meteorainer mentioned, PHP offers a pretty simple solution for most of what you need to do, and is much less complicated (in my opinion) than Java or .NET. I also believe it to be much easier to get started with.
As far as pointers go, a lot of what you need to accomplish can be found in the PHP manual itself, along with code samples. For example:
File uploads:
http://php.net/manual/en/features.file-upload.php
CSV Processing:
http://php.net/manual/en/function.fgetcsv.php
or, the method meteorainer mentioned
http://us3.php.net/manual/en/function.explode.php
MySQL Databases:
http://us3.php.net/manual/en/book.mysql.php
http://us3.php.net/manual/en/function.mysql-connect.php
Creating new files:
http://php.net/manual/en/function.fwrite.php
As far as whether or not this is a sound system, that all really depends on what this is going to be used for. I may be wrong, but it sounds like you just need a simple application for a very specific use. If this is the case, I would say it sounds just fine. You can always expand upon it later on if you choose to do so. Adding more security measures, more robust output, things like that. Either way, at the very least, your PHP implementation sounds like pretty good starting point to me.

Ya php can definitely do what you are looking for. You'll be using functions like:
$variablesArray = explode(file_get_contents('uploadedfile.csv'));
To bust open the CVS into a useful array and do some storage/math to that. PHP is definitely your bag.
You have other options, like java and asp, but imo java is far too complicated for what you get out of it, and asp requires a .net license and again, grants nothing over FREE php.

Related

What options are available for debugging server scripts?

I'm a self taught programmer and I consider PHP one of my strongest languages. There are undoubtedly some things I don't do correctly though, since I'm not in the field and I've never had anyone leaning over my shoulder telling me about better ways.
The most cumbersome thing to me about php is debugging code. It's not too bad when I'm writing a script called with AJAX or php code inside of a webpage, because I can simply output values directly to the page. When I'm writing code without a client side though, I currently resort to outputting my debug info to the error_log. I have to navigate to it (which sometimes is a task in itself, refreshing directories to make it show up, etc), check whatever value I outputted to it, then open up my script and start working again.
I feel like there might be a better way, so I thought I'd ask. Is there a trade secret that can shave some seconds off whenever I need to know how many rows a query returns or if a path has been constructed correctly?
My development environments are Coda on my MacBook and Zend on my PC. I work on everything remotely. Nearly all my code requires the server environment to run correctly.
Update
After writing this, I just realized I could actually make a webpage using WebSockets that acted as an output window. Then import a file into each script with a function that pushed output to the webpage. Hmm... I really like this idea actually.

Generate DB usage in PHP Scripts

This might seem to be a silly question but I was wondering if there any programs out there that would scan over a directory of PHP scripts and generate a report that states exactly what databases and tables are queried in each particular script?
Our database type is MySQL. Thanks for your help.
You might try something like PHP Code Sniffer. It's a static analysis tool that can search through PHP code for certain rules. You may have to end up writing your own sniffing rules, but it might be somewhere you could start. I've used it to check PHP version updates and it's worked pretty well. Just search for 'php code sniffer custom standards' and you can find some useful stuff to help get started.

XML with PHP instead of MySQL for first time

I've always used MySQL with PHP and on my site I added a chat system that uses MySQL which as you would know is VERY database heavy so I think I'm going to switch it over to XML files for each user just for the chat system to take all the load off of the DB.
I have never used XML with PHP before so I was looking for information, and found that the queries are pretty similar to MySQL.
Here are my questions:
Is it the client writing to the file or the server writing to the file?
Do I have to chmod them as 777?
Do I also have to chmod the XML file as 777?
If I do have to set the permissions to 777, does that drastically decrease security and is there any way to tighten that up?
Does anyone have any tutorials they would recommend me to as well? Most of the stuff I found is from 2003 - 2005. Don't know how much has changed in it.
Hope it's cool I ask this question here.
Thanks a bunch
-Sal
First off, it seems like a very bad idea to do something that is very database intensive in xml, it is going to be a lot more intensive that way.
To answer your question; It is always the server writing to the server filesystem. you only need to provide write access to the user running apache (and consequently php).
I suggest you stick with mysql for chat but look into DOMDocument to learn more about xml

build PHP with ant scripts

I was just wondering how I use Ant to build my web applications that I have written in PHP? I've googled around a bit and I have seen that it is possible but there are not any examples of the basic idea or any advanced use for them. Can any of you help me out?
Thanks!
This is definitely possible. If you are looking for a pure php solution phing might be what you want. Also note that there's usually no reasons to build PHP scripts. They should 'just work'.
While Ant itself is written in java, you can use it to build any kind of applications you want. Here's a basic tutorial and a full manual. Beyond that, you need to clarify what is it you want to do to get a more precise answer here.
Update (based on question clarifications):
Copying / moving files / folders is easy via Ant. Look through the "Hello World" tutorial I've linked above and Familiarize yourself with FileSet concept and Copy, Mkdir and Move tasks to get started. Here's another tutorial that shows how to set up a basic build (ignore java-specific stuff like javac/war).
Making changes to the database is an entirely different subject. If you have 'alter' scripts ready, you can use Ant's Exec task to invoke your DB's command-line client to run those scripts (though I probably wouldn't do it in production). If you want to use Ant to track those changes, then you're looking at the wrong tool. Liquibase can be used to do that and it seems to be getting a lot of traction lately. It's quite like Ant in the sense that it's written in Java but can be used in any environment. I'm no PHP expert so I wouldn't know if there's something more PHP-geared available.
We use ant to 'build' php apps. At it's most basic, the ant script just copies the file into the folder on the testing webserver (localhost in my case).
Why do this? well there's not a great deal of point to it, but it is a handy way to avoid putting .svn files into the webserver. If you want to change the location of the webserver you can just build to the new location. You can also do different things according to whether you're on Linux or Windows for example, but I've never used that side of it.
Having tried Phing, Ant and Gradle, I would strongly recommend gradle. Here is a bit of description Choosing tools for PHP application automation

Best Practices for locating a function definition in PHP

Is there a simple way to find the file path to where a function is defined? I currently use dreamweavers FIND in an entire directory. Would be nice to have something that doesn't require downloading the entire site tho.
Any suggestions?
Personally I use an IDE like Netbeans or Eclipse PDT. In the case of Netbeans you can ctrl-click on a function and it'll take you to the definition. Sometimes there is a choice in which case it'll make you select one.
But its generally bad form to reuse a function name within your code in different files. It can lead to hard-to-find bugs because it's hard for any program to figure out exactly which one function is actually getting called since source files can be included dynamically.
Would be nice to have something that doesnt require downloading the entire site tho.
I hope this doesn't mean that you're modifying the site remotely.
Have a local working copy, make the changes, test them locally, then upload the changes.
A simple combo of vim and ctags makes the "go to definition" task a piece of cake.
You can't search for something (and expect to find it) unless you have a copy of all the files it might be in.
A number of IDEs have the ability to click and go from a use of a variable or function to its definition. If not that, then a multi-file searching tool within your editor, or something from a command line (such as ack) that is a little more specialised at searching source code can help. Good naming conventions can also help a lot for consistency.
It's not the question, but why don't you have a copy of the site locally - and while you are at it, keep it in version control as well?
I'd sure like this get_functionPath() ability and anyone that has extensively had to work on other people's code would probably find it incredibly useful. We have function_exists, if that could simply return the file the function is defined in for user defined functions it would save a TON of trouble. No, not all of us use IDEs, and yes some of us have been doing this long enough to code on the production machine. Test boxes and sandboxes are for rookies.
One trick is to purposely trigger an error in the function you are trying to locate. Can save a ton of time.
You'd need to use some kind of tool that could build an index on a remote filesystem that you could download and perform local lookup and search upon. I don't know of anything that can do this and a few moments with Google didn't turn up anything.
Maybe a good idea for an open source project? hinthint
so there is no function that would do this? Something like get_class() which would output the parent class but in the case the file path on the server...

Categories