Creating an API (with PHP) [closed] - php

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I been having this idea spooking around in my head for 2 weeks now. I’ve finally created some cases and plans on where I want to go with this project. I will have to create both a web application (ASP.NET) and a desktop application (Java). Both these applications will need to have sync’d databases.
I’ve been thinking about creating a public API over my database so my front-end and 3rd parties could communicate to the database. But I’ve never really attempted something like this before. I’ve spend my weekend so far on reading up on how I could approach this and I’ve gotten a pretty good idea. I’m having some questions/doubts currently and was hoping perhaps someone could help me.
1) I’m currently still in university and I don’t have a job so my pockets don’t go very deep. I’ve been thinking of writing the API in PHP, I already have possession of an unmetered hosting account and else I would be forced to buy .NET hosting which can turn out to be quite expensive. However my PHP knowledge is quite limited towards parsing user input/security. Would it be wise to search for an (e)book around this topic or would I be fine with online tutorials, do you have any suggestions on where to look? Should I put my time in writing a possible vulnerable PHP API or should I look at other options?
2) So far I’ve never really had the need to look into PHP libraries. I was wondering if I should look into some of these (for example cakePHP) to help me develop the API.
3) I’ve experience with implementing Twitter/Linkedin their API’s so I’ve been thinking to use OAuth (v2) to allow people to use my API. Is implementing OAuth to your API a lot of work? Is it well documented enough for someone with only basic PHP knowledge? If you ever used it on your API, what was your experience with it?
4) If this project would ever kick off, it would be wise to look into hosting It in the cloud. Do I currently need to think about something so future cloud integration is possible?
5) For the web application, would there be a (big) performance difference between using the API or directly connecting to the database?
6) Any recommended lecture or tips are welcome. It’s the first time I will be attempting something this big (both in functionalities & required knowledge).

1) Developing a simple API is not that hard with PHP if you have some experience in other languages. Ofcourse, every language has its own way, and when it comes to optimization and stuff like that, you may need some more PHP knowledge.
2) Using a PHP framework would definitely help with the lots of aspects. I use symfony 2 for all my PHP projects. I really suggest checking it. It's a decoupled framework, and you can use individual components from the framework. It's lightweight and fast, and offers great tools to build what you want. What is symfony? explains the benefits. Also, using ORM (I prefer Doctrine) is an option, but this is a whole another topic.
3) If you decide to use symfony2, there are bundles (libraries) for it that you can use. It shouldn't be too hard to implement even without a framework, but I don't have any experience in that area.
4) I don't have any experience in cloud, so can't comment on that.
5) There will be a performance difference as you are adding another layer to your project, but whether it will be a big or small depends on the API, database etc. But, using an API will mean a standard way to communicate with the database, so even with the performance difference, it might be beneficial in terms of consistency and development time(you won't have to deal with different platforms to do database stuff.).
6) The usefulness of the API greatly depends on the application and I can't really say if it outweighs the costs without specific information about the project. But having a standardized way to communicate with the data storage is generally a good idea when dealing with multiple platforms and languages IMO. As I don't know how much do you know about PHP, I can't comment on if it will be worth your time. I would go for it if there is enough time, as learning about PHP would add some more tools in your arsenal and this will be a good opportunity to improve yourself as a developer.

Related

Best solution for a database driven web application? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
I have been planning out the development of a web application written in PHP using the CakePHP framework. This application will be heavily dependent on a SQL database. The primary intent of the application is to provide HTML forms for adding, managing, and removing data from this database. It will be a descent sized database (1-2 dozen tables) and there will be a good number of links between them. There may also be some reporting on the data (would like to export to Excel/CSV or similar).
So here is my question, does anyone know what solution would be best for this type of situation? If this application was developed fully in PHP/CakePHP it would take quite awhile to develop by a single person and require the input of a developer to add/remove/update the database structure/fields. However I can provide much more custom interface tailored for the needs of the application and it will be web based (accessible anywhere). But there are also solutions such as Filemaker Pro that can provide a similar solution. Does anyone have experience with such applications and solutions?
I develop web applications using CakePHP and MySQL Full time for my current employer, so I'll try to answer your questions from experience:
does anyone know what solution would be best for this type of situation?
Any PHP Framework is a great solution for your problem model. I prefer CakePHP because it allows me to rapidly deploy applications, and it favors convention over configuration.
If this application was developed fully in PHP/CakePHP it would take quite awhile to develop by a single person and require the input of a developer to add/remove/update the database structure/fields.
From what you're telling me, your application will be mainly a CRUD app. A CakePHP installation comes standard with the features you need for this. Even better, you can use the CakePHP Console to "Bake" your application. This will automagically generate all of your Models and Controllers, and all of the views you will need to add/update/delete records from the tables.
The only preparation you need to Bake the app will be:
Creating the Database
Naming all of your tables following conventions from the documentation.
Ensuring you have all of your foreign keys in the proper place, following naming conventions.
At this point the Bake Console will get to work building models, discovering relationships, and generating code for CRUD operations. That's right, you'll be 70-90% DONE (based on your current, vague specifications) with the functionality in about 10 minutes after building the database. From there you will need to flesh things out with your own designs, security, and functionality like reporting.
It really is easy.
Now that I've said all of that, you'll need to know a couple of things:
To properly optimize CakePHP configuration takes a bit of experience and/or magic. Getting your application up and running is a veritable piece of cake. Making it run well takes some effort to make sure you use best practices. Search for variations on "Optimize CakePHP" in google and review the blogs you find.
The Containable Behavior is a blessing and a curse. By all means, put it in your AppModel to make everything "Containable." But, try not to use containable to find data from deeply associated models. Cake will barf out a few hundred (or thousand) Select queries, and your app will start to crawl/fail.
You can try out the Agile Platform by OutSystems. You can model your web applications visually (including all database details, web pages, logic, ...) and then generate a standard .Net application using a SQL server database.
Once you define the database structure, you can drag&drop tables into the pages to automatically create CRUDs. This greatly simplifies the implementation of web pages that manipulate data. These " wizards" will also create all the pagination and column sorting (when you're listing data from a table), as well as the pop-up forms (with field input validations) needed for users to input data.
Last, but not least, if you make changes to the database structure, the platform will automatically update all pages and logic (like queries) that you are using, and will pin-point all the elements you need to manually change to ensure the app is consistent.
You can download the Agile Platform for free at http://www.outsystems.com/download/ and give it a try.
Cheers
Michel
PS: I work at OutSystems

what is best practice for php software development? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
as web developer using PHP/JS/CSS for years , i suffer from repeat myself over and over and over and over , even if i use a PHP framework , i feel the same thing every time, i start to build new feature , so every time i started new thing i feel the 'Déjà vu' ( i write it before ) , and i rewrite many things from scratch despite i write something same before , if i use previous written code , i may take more time to reuse it , i love programming and web development , but by this way i will lose this :( ...
Where the problem ? in language , my way to built software or what ?
if i use previous written code , i may take more time to reuse it
This, I believe, is your real problem: you're writing way too much quick-and-dirty code and are suffering from the resulting techincal debt. The problem is, what is quick in the short term can lead to being very slow in the long term.
If I may offer a non-technical comparison, consider a Ferrari and a cargo ship. When delivering just one letter, it seems obvious that the Ferrari would be much faster not to mention much more convenient compared to using a cargo ship. Just loading the ship before leaving the docks can take hours. By which time the Ferrari would have already completed the delivery. But when you have to deliver a hundred tons of mail, the cargo ship would complete the delivery while the Ferrari would still be busy speeding back and forth delivering each letter.
It's the same in your case. When developing just a single web site, it will always seem obvious that you should write the least amount of the simplest possible code to get the job done quickly. And if your whole career is devoted to just one web site I would even say that that's the right way to do it. It is, after all, the essential spirit of Agile methods. But if your job is to develop websites (plural) then this approach will start to become slower with each new site. Just like how the Ferrari is not ideal for delivering a hundred tons of anything.
One real world example is 37signals. When their business model requires that they should be able to quickly develop and deploy sites as necessary, instead of just diving in and develop their first site in a quick-and-dirty way, they took a step back and developed Ruby on Rails instead.
I'm not saying that you should go ahead and start your own framework, re-inventing the wheel is exactly what you want to avoid at this point. What I'm suggesting is to separate the functionality you're developing from the web related code. In other words, when writing new code write it as a library. Yes, it's a bit more involved writing code in two or more files compared to inlining the functionality directly in the PHP page. But in the end your next web site would be easier/quicker to implement.
I always, as a matter of habbit, create a lib directory in a project's base directory whenever I start a new project. I then force myself to write all code even remotely reusable as separate modules in this directory. These days I find that, more often than not, I'd simply copy (or more commonly make a symlink) of files I need to the lib directory instead of writing the needed code.
The problem is that when PHP started, every tutorial, every demo and all code was made in a very structured way, because PHP descended from the C/C++ family. Many developers took this problem and have carried it, and it was visible that we couldn't keep this.
Now, we have PHP 5.3.3 available, we have namespaces, objects, classes, interfaces and all of this. Many of the things that helpt making bad code like magic quotes and register globals are now deprecated. PHP is evolving into the OO world, it took long enough, but is happening. So if you want to start again to "relearn" PHP I would suggest getting your hands on some frameworks like:
symfony, joomla, propel, doctrine
learn about mvc and design patterns applied to PHP and you will see how you'll start making good OO code, and the deja-vus might stop before you knwo it.!
Hope I can help
David
This is exactly why a framework is the best way to go. It takes out the mundane parts of code (the stuff you always have to write over and over like DB connections).
I would suggest picking a good framework (I use CakePHP, but there are others like Symphony, Codeignitor, Zend, etc.), and as you build various components, you can reuse them in other projects. It will reduce the time it takes to write all future projects.

When a Web framework isn't convenient to use? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
When a Web framework ( like django, ruby on rails, zend, etc ) isn't convenient to use ?
And so... When a Web programming language ( like PHP, Asp, Python, etc ) is better than a Web Framework ?
I like the wikipedia description:
The framework aims to alleviate the
overhead associated with common
activities performed in Web
development. For example, many
frameworks provide libraries for
database access, templating frameworks
and session management...
Basically if you don't need all of the above, you don't need a framework.
You don't need frameworks when you don't plan to use their features.
The difference is, in my opinion, the simpleness of what you are trying to build.
Are you trying to make a difficult, complicated web app, or are you making a simple script that performs a trivial task? In the first case you absolutely need a framework, in the second case.. don't even bother.
The rule that I have is that if whatever I'm building is only going to be a single page, I'll usually do it in just PHP. Whenever I need more than one page, I go with a framework (Symfony), because that usually means that I'm going to want things like routing and proper dispatching of requests.
This does however depend a lot on the language. In languages like PHP, the time needed to set up a project to use an MVC framework may be a lot more than just solving the problem. Other languages may very well be designed around using an MVC framework, and has a very low setup cost for that.
A web framework is supposed to provide means to handle certain kind of interaction. If you have site with no interaction or no "adaptation", you don't need either framework or programming language, you simply write HTML files and publish your files.
As you start to add features for the back-end (like publishing more plain pages) or in the front end (like sorting a list when the user clicks "order by") you start getting into frameworks/programming languages.
Basic interaction was handled with CGI - you write an script which responds with a string to a few parameters passed via a form. Then you have database access.
In my experience, if you need simple features AND want your website to be suitable for growth without resorting to rewriting it from scratch, you should start from a web framework like Django. You can do simple things quite easily in Django (granted - it is not trivial) and add very complex behavior with small, incremental steps.
When you have to build a very complex site, and the functionality is already exists in a CMS (eg Drupal, it has amazingly lot contrib for everything).
I'm at that stage where, because I spent so much time learning a framework recently, even if I do a one page "website", I will still use one, need to get my ROI up :p

Becoming a professional PHP programmer. How? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
I'm working on my first professional project. The fact is that I don't know which are the best tools to produce something serious (I'm talking about web-develop through PHP):
Are template engine like Smarty mandatory? Which one is "the best" (the most used, complete, documentated)
At the moment I'm developing on Notepad++ (mostly because I find it useful and complete) is there a better development tool? Or is just a matter of personal taste?
At the moment I'm studying JQuery and deepening my knowledge as regards CSS what other "mandatory" subjects can you suggest me?
This is what I can think of at the moment, have you any other suggestions?
Thank you.
EDIT: As someone made me notice the question is a bit ambiguous. I know the basics (HTTP protocol, Java Script, CSS, HTML, OOP theory and practice etc...). I'm studying computer science at the University (and the project I'm speaking of is my thesis). I need advise on how the "real world" works (outside my basement).
Don't focus on becoming a Professional PHP Programmer. Focus on becoming a professional web developer, and check out the What should a developer know before building a public web site? question.
Saying "I want to become a Professional PHP Programmer" is like saying "I want to be a professional painter" when you actually mean "I want to be a professional artist." Sure, at the end of the day both might paint and get paid for it, but what their customers expect of them is very different ;)
Specifically for PHP I'd recommend:
Learn a good framework. Depending on the size of the project, you can use Zend/Symfony or CodeIgniter/others for small ones. There are tons. I'd stick to Zend/Zymfony for something mid-sized and/or "real world".
In general these frameworks come with a basic template engine or you can plug in other ones like Smarty or Twig. I'd say it improves the code a lot. So, yes to your first question.
Also, notepad++ is amazing, but I recommend using an IDE if you're working on a project and not a simple 2,3 file script. I strongly recommend Netbeans. It has lots of teatures and it's really active. Check it out: http://netbeans.org/features/php/
Since you're coding in PHP, I'd say you get to know the SPL (Standard PHP Library): http://php.net/manual/en/book.spl.php
To sum up:
Strongly recommended to keep code clean and mainteinable.
Yes.Netbeans.
Yes. SPL, and a lot more I can't think of now.
A templating system like Smarty isn't mandatory, since PHP is technically a templating system. However, it's not a very good one. It's clumsy, very easy to make mistakes with, and you frequently end up with an incomprehensible mess.
There are better alternatives than Smarty out there. I'm kind of partial to Twig, myself.
Using a framework is pretty much mandatory these days. Development with a framework is generally much easier and quicker than using raw PHP, once you've got the hang of how it works. Code Igniter's pretty good, although minimal. CakePHP is quite good, although seems very heavyweight at times. Kohana, Symfony, and the Zend Framework are pretty highly regarded as well.
1 - The Smarty engine is very useful and probably the most popular in PHP application development.
2 - I use Aptana studio for PHP development. It's pretty complete and has nice tools coupled with it. It's based on the Eclipse IDE, so it's pretty customizable. The major drawback is that it uses a lot of resources.
3 - I recommend learning development patterns like MVC (Model - View - Controller) to get a good base of how data should be organized.
Also, look up Code Igniter, It's an amazing framework to work with (it uses the MVC pattern). Building something with it is really easy and very easily manageable. If you want simple tutorials, you can check on NetTuts for a serie of tutorials.
Agree with what Pekka is implying, which is that it's important to pick up another lang in addition to PHP. Please. Also, I can't see learning PHP without knowing stuff like Smarty. Notepad++, who cares there, each to his own. jQuery is fine though I might opt for plain vanilla Javascript before getting into a library. Even though jQuery makes things easier it abstracts a lot of stuff and what you really want is those Javascript mechanics.
I would also add a solid knowledge of the HTTP protocol as a must-have that some web devs seem to think is optional. You should know what a hard 404 is, and what content encodings are, and the different flavors of caching disposition, etc, etc, etc.
Above all, have fun!
Most web development includes some degree of database interaction, so good DB skills is always useful.
Basic normalization of tables.
Understanding Transactions
Knowing how to escape your values
before insert/update/etc
write selects with joins how to avoid
nesting database selects within code
loops
differences between database
and PHP dates (and how to work with
them)
etc
My standard recommendation in questions like this, in addition to the excellent suggestions given in the other answers already, is to at least dabble with a strongly typed language like Java, C++, Delphi or C#, with a merciless compiler enforcing discipline - proper declaration of variables, definition of complete class interfaces etc. etc. I love PHP, but it is very permissive and sometimes still shows its templating language roots, and tends to seduce newbies into bad practices. (That said, PHP nowadays is a fine language and it is well possible to write very high-quality software in it.)
However, you say in your update that you do Computer Science at University, so I guess you are already getting your helping of at least one other language, and CS theory, and your focus is indeed which frameworks to use etc.

Where can I learn web programming from start to mastery? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I tried doing tutorials but it is unorganized and unstructured, where can I learn PHP from beginner to master? I'm looking for a site like www.w3chools.com, but somehow I feel it is incomplete, specially when it comes to more advanced functions.
I know some basics but I wouldn't be able to for example make a secure online webstore, and I seem to be stuck at this point, how / where should I proceed?
I started 7 years ago. In my personal experience, your road to programming will look something like this:
HTML -> CSS -> Javascript -> PHP/MySQL
[Insert other web script language
here] -> "Desktop Languages"
For HTML (and CSS), I started by using a graphical editor at (then freewebs.com) webs.com that allowed me to add code snippets. I used some random GeoCities site (may it rest in peace) to look up things. Now, use Google or Bing.
Then, I got Jeffrey Zeldman's book, Designing with Web Standards. I followed through the book, typing out the code in notepad. Try to understand what the code does.
Do yourself a favor, use Notepad++ or Programmer's Notepad. They support automatic tabbing for neater code. It will make you a better and more sane coder in the long run.
Another thing I used to do was look at people's code by right clicking in my browser and hitting "view source".
This only gets you the HTLM/CSS after the PHP has been run and the Javascript before it was run. Google Chrome is good for analyzing scripts because of the debugging capabilities. (Don't worry about that yet though.)
Javascript was an adventure back then. Now, we have jQuery. Start with that or a similar framework. This can be researched online. I have never bought a Javascript book. I do have an ancient one from Visual Quickstart that I used to learn what a method looks like. Beyond that, the particular book in question is
an outdated rag.
To learn PHP/MySQL you can get a book. The two languages are often put together so finding books that show you how to use them in tandem should be a snap. I used O'reilly books for PHP.
I don't like the online PHP reference so much, because when I'm testing I don't always have internet. I use a virtual server setup on my machine. Look into that when you are ready to start learning PHP and MySQL.
The last thing to remember is that web standards are always changing, but don't get too crazy about it. when I started, XHTML was all the rage and now everyone is talking about HTML5. I still use XHTML as do many others. It goes to show that things move at different paces for everyone.
Good luck, I hope I helped!
EDIT: Geoff Adams pretty much sums up my post - Play around the invest in books. And, it will take time. I'm till nowhere near perfect.
Getting to 'mastery' is going to take a lot of effort, time and work. You can't become an expert by simply reading tutorials - the best way is to learn by doing. Get to grips with the basics, then play around. Once you're more comfortable, invest in some books.
If you're looking to build a complex system then you might be better using an off-the-shelf alternative. Try Googling around for various e-commerce systems (Magento is in vogue at the moment) and Content Management Systems (CMSes) before you decide to reinvent the wheel.
Read this book
also keep going through those tutorials (XHTML, CSS, Javascript) and try out everything you learn as you learn it.
I love the apress books so perhaps Beginning PHP and MySQL: From Novice to Professional, Third Edition might be for you? Do you have a development background?
You may want to look at picking up a book at your local book store or look at grabbing one off Amazon.com. I haven't found really good PHP web resource to learn from. Usually I just do a quick google search on topics I'm trying to code.
Another option is to just dive in and start building applications. I've found that the best way to learn PHP is to learn as you go. Once you have a grasp on the basic syntax and how to move around the code, then you can pick up a book at look at OOP topics as well look into Frameworks such as Zend, CakePHP, etc.
Are you absolutely set on learning PHP? If you are, then buy a good book - there's several mentioned here that are actually ok - but please, learn the security aspects from the start. There's more than enough PHP developers in the world who are writing insecure code (I used to be one of them, so I'd know).
Practice is key though; I've been programming in PHP now for about 6 years, and I'd consider myself fairly competent (I passed my Zend PHP5 Certification a couple of months back), but I still find functions I've never seen before.
A tip - don't even think of looking at Zend Framework, Magento or anything like that until you're comfortable with the basics. If you do, you'll definitely struggle; they use some advanced concepts which even I find it hard to wrap my head around at times.
Alternatively, you could learn something else...
The book recommendations are great. "Mastery", though, comes only from practicing your craft. If you want to learn PHP, you need to build many sites, with PHP (and HTML, CSS, Javascript, MySQL, etc.).
To have confidence that you can build a secure online web store, well, you need to build one. Maybe you can find a company that will pay you to learn. Maybe you will find a colleague to mentor you through it. Or maybe you'll have to dig into books, multiple web sites, and some poorly written "integration guide" from a payment authorization provider. My first time through I was nervous. The second time it went a little quicker. And the third time I felt confident enough to estimate how long it would take.
I'm not trying to be difficult or flip. I just feel that "learn by doing" may be the only way to learn much of this stuff.

Categories