9 ms·
I teach web development at a university. We have used, java, javascript, python and php for a basics course in webdev. Php has built in web features and one do
by la_fayette 7y ago
I teach web development at a university. We have used, java, javascript, python and php for a basics course in webdev.
Php has built in web features and one doesnt need more than a php interpreter (considering the built in web server as well) to get started. For all other languages i know of, there is quite a process to get started (e.g. start with python flask one needs a package manager, environment variables, command line experience, ...). Php is a web native language and great for learning and getting started.
Considering professional development (https://en.m.wikipedia.org/wiki/Programming_languages_used_in_most_popular_websites https://en.m.wikipedia.org/wiki/Programming_languages_used_i...) it seems that it doesn't matter what language one chooses, various different stacks are used by the most popular websites..
- penagwin 7y ago> needs a package manager, environment variables, command line experience Is this not the same with PHP? If you want to use packages then you'll need to use a Package manager, you still need command line experience etc. Node.js comes with a package manager NPM, and has no need for anything like virtualenv's to keep packages separate per project. Python doesn't need virtual env's at all, it's just good practice. And to be fair, as a naive non-PHP user, I have 0 clue how you would go about setting up long running scripts that don't necessarily correlate to a web request.
- CiPHPerCoder 7y ago> If you want to use packages then you'll need to use a Package manager, you still need command line experience etc. PHP has a package manager IF you want to use the vast offering of open source PHP libraries and frameworks. https://getcomposer.org/download https://getcomposer.org/download To use it, create a composer.json and run: php composer.phar install On my systems, I like to alias it so that I just have to type: composer install Alternatively, if you use a Jetbrains IDE (i.e. PHPStorm), you can usually install dependencies with one click. > And to be fair, as a naive non-PHP user, I have 0 clue how you would go about setting up long running scripts that don't necessarily correlate to a web request. php /path/to/script.php It can run as long as you'd like. If you want to do it on demand (i.e. writing a webserver in PHP), that's difficult. But generally: Why would you want to do that? It becomes an X-Y Problem.
- fbernier 7y agoI don't think the person you're replying to said it was not possible with PHP. Just that similarly to other languages where it's just as straightforward as the example you gave, it's not built-in.
- CiPHPerCoder 7y agoThey said "I have no clue how to X" so I told them how to X, with caveats for corner cases. I wasn't trying to debunk a claim that something is impossible.
- stickfigure 7y agoso I told them how to X No, you didn't. What you probably meant is "run it from cron, or create an OS service that starts from init.d/systemd/whatever". Which answers the question, but isn't very impressive from a technology stack.
- CiPHPerCoder 7y agoNo, what I meant is: Run this command. It can run for as long as you want it to. That's a long-running process, by definition. If they wanted something more specific, they should ask for what they really want.
- Piskvorrr 7y agoExcept that "PHP is meant to die", i.e. doesn't perform well as a long-running process, you'll keep running into bugs and warts. Software Gunslinger has explained that well: https://software-gunslinger.tumblr.com/post/47131406821/php-is-meant-to-die https://software-gunslinger.tumblr.com/post/47131406821/php-...
- penagwin 7y agoI kinda meant both. I feel silly not knowing that it's only "php ./script.php". I also meant long-running processes, which it sounds like is still problematic. To be fair, it doesn't sound like PHP was ever designed to be used for long-running processes, to which I guess "Fair enough", but that might make things like a job worker queue more complicated if you want to write the workers in PHP (it sounds like you'll need a dispatcher in a different language because that would be a long-running process).
- darkhorn 7y agoHe means for example if you want to make database connection PHP has build-in function. But in Java you need few libraries. In one end it is one line code, in the other one it is several lines of code.
- mdasen 7y agoThe thing about PHP is that the language has built-ins for almost everything you need for classic web development. Want to use a relational database? You don't need to install a library (often one that requires a C extension in a language like Python or Ruby). It's just part of the language. Just do `$mysqli = new mysqli("localhost", "my_user", "my_password", "world"); $result = $mysqli->query("SELECT * FROM x");`. Want to get things out of the HTTP request? PHP has already parsed everything into the `$_REQUEST` associative-array (map/dictionary). You don't need something like Flask or Node to deal with decoding the request. Cookies, response writing, uploaded files, GET/POST vars, sessions, and many more things for web development are built-in. Heck, PHP even simplifies templating because PHP is literally its own templating language. If someone gave you Python without any packages, would you be able to handle a request, see a GET variable, and put it into a page? I haven't used PHP in a decade and I can immediately think how to do that. OK, create index.php with whatever HTML I want in there and then put `<?= $_GET['theVarName'] ?>`. Done. That's it. If I want to get something from a db based on that get var, it literally has the functions/objects to connect to and retrieve stuff from the db. With Python, are you going to write your own database driver? With Python, are you going to open a socket and start manually handling all the HTTP stuff? I'm not arguing that PHP is a better language than Python. I'm just saying that it was literally built to handle web requests and create the kind of web app that a lot of people make. The point is that with PHP, you usually don't need to do anything. You can just create a file with the `.php` extension and put in bits of dynamic code and the language has everything you need to create an app of the kind users expect without having to add libraries. Does this matter? I don't think it does most of the time. I think OP's point was that PHP gets new people from nothing to "WOW, it's showing up on the screen!" with almost no effort. "OMG, I can save the form to the database and then display the information!" Tools have gotten a lot better for a lot of languages over the past decade. Still, nothing beats the ease of not having to deal with anything. PHP offers that. PHP also offers a dead-simple deployment. You put your files on a server with PHP installed and you're done. Lots of shared hosting supports this precisely because the PHP language includes most of what people want to use. Because the language includes these things, that code is shared between all the users on the server rather than re-parsed and re-stored in memory and re-executed for every user. I mean, if a bunch of people are using Python, they're all going to bring DB libraries with them and many will be slightly different versions, etc. Likewise, some will use Django, some Flask, some other libraries - and again, all different versions. That makes hosting a bit more expensive (though that has gotten cheaper with serverless). Most of the time if you want a library, you can download a directory of files and then use `require` or `include` to bring it in using relative paths. No worrying about environments or installing things. Just copy a folder! That's the thing about PHP: it's basically a language and web framework in one with a simple development model. I don't think PHP is a great language. However, I think it's important to understand why it was so successful. Back in the day before Xen and VPSs, it was hard (expensive) to get a server with root or get someone to install a package on a server for you. Virtualenv wasn't around forever (I remember easy_install before pip). You'd come across things that you just couldn't use. You'd end up fighting with a lot of things. You'd have to start long-running processes or use fcgi or all sorts of things that were annoying. Today, it's a much better landscape - partly because tooling has gotten better and partly because compute and RAM costs have gone down. But back in the day, you could just stick an `index.php` file in a directory set up for you and go to town. Instant gratification with zero setup. Even today, we use tools like NPM, Yarn, Virtualenv, pip, RVM, Gems, etc. to manage things. And I think that libraries are a lot better than having all those things built into the language. However, if you're looking for someone to be instantly productive on a live server, PHP does that. You never have to reload things or stop processes or set up a reverse-proxy. You never have to install anything (presuming the server has PHP set up). Again, I think that libraries are better. They let you upgrade code without a language update. I think package managers are better than just downloading directories and copying them into a folder. I think that a long-running processes has a lot of benefits over re-evaluating the code every time (and PHP has modes that support this, I believe). But the interesting thing about PHP is that you don't need to do any of those things which do incur cognitive overhead. I mean, I don't want to be a PHP programmer, but if you're looking to take a student with one CS course under their belt and give them some instant joy, PHP really hits the mark. Even the way you can program simple things is so easy. Ok, we all get directory trees and so if I go to `/apple/pear.php` the web server will execute that file. I don't think that routing in Flask is that hard, but there's more indirection. We can just go to pear.php and make it whatever we want. Again, this isn't about clean design and many advanced PHP projects use their own routing. This is about someone who doesn't know much being able to access GET/POST variables, call functions with SQL statements in them, and generate some HTML. No MVC, no DRY, no whatever. Just code that executes top to bottom in that file. Maybe you've used `require` or `include`, but again, that's just like copy/pasting that file at that point in the code - and it can be done anywhere and do anything including output HTML. To be fair to PHP, I don't think good PHP is written that way. I just think there's a somewhat special simplicity to being able to just start writing random code in a file and have a web server execute it - and that code can do real stuff. No libraries, no configuration, no worrying about how the whole application is laid out. Just a file that executes. And before VPSs and such, it was so much easier. If you don't remember years like 2008, there are amazing threads about people trying to deploy things like Rails apps and the problems they encountered. It wasn't like today where we have much better tooling - but PHP always just let you upload some files that it would execute. Sorry for this rambling thing. I don't think you should be learning PHP or anything, but I'll always have a bit of a special place for it because it made programming real things really accessible when I was an undergrad. I wasn't going to be renting a server with 1GB of RAM for $100/mo to run a Java project. Even a smaller server to run some Ruby or Python would have been more expensive and required a lot more work (which, frankly, I wasted a lot of time doing out of interest, but that's beside the point). PHP let me get something for $5/mo and just stick files on a server that someone else admin'd that would just work. I didn't have to do security patches, monitoring, process management, etc. I could just write some files that spit out some HTML, read GET/POST vars, handled sessions and cookies, connected to databases, etc.
- msla 7y agoYou'll eventually need a package manager. The only question is whether the language ships with one, the OS does, or whether you're on the hook to provide all package management by hand. I agree that PHP lets you go a bit farther without one, however.
- Supermancho 7y agoComposer (getcomposer.org) is the package manager of choice for php.
- badrequest 7y ago> it seems that it doesn't matter what language one chooses "there is a successful website written in X" does not mean that it is deemed appropriate or acceptable to use whatever you like. Anybody who has started a new project from scratch as a professional at a company can tell you it absolutely does matter what language one chooses, and if you opt for something non-standard or for whatever other reason deemed unsuitable, you will be corrected.
- goatlover 7y agoPHP, Ruby, Python and JS and their popular libraries or frameworks are standard for web dev, though.
- Glyptodon 7y agoI agree PHP is vastly better than it used to be. It is also a bit more "batteries included" out of the box if you're doing things in a very very bare standard library/simple server sort of way. That said, when learning web development, PHP, Python, JS, and Ruby are all very similar. You absolutely use a package/dependency manager of some sort, and they all have pretty simple startup with their major (similar) frameworks, whether Laravel or Django, Yarn or Bundler, etc., for their respective languages. That said, there is one place where PHP is very different, and that is configuration. PHP still has a lot of configuration options that live in global config files, and a number of things that could be easily managed dependencies or are core in other languages are still extensions that need to be installed and enabled at the language level in PHP which seems worse from a "getting up and running" perspective.
- pathartl 7y agoNot to mention that actually debugging with PHP is a pretty big chore.
- memco 7y agoI recently switched to working with Python over PHP. When I started working on this project no one on the team used a debugger nor knew how to set it up. VSCode became the easiest path for debugging so I use that but it doesn’t handle multi-threaded code well yet so it’s been a bear trying to debug. On the other hand. I added three lines of xdebug config to my PHP.ibi and I can remote debug the PHP stuff no problem. Granted it doesn’t have as much introspection as other languages it was still a much less painless process to dive in and see what the code was doing. On the framework side, Laravel beats the pants off Flask or django IMO when it comes to deployment, asset build pipelines, queues and database migrations. Almost all of those can easily be configured with laravel and are very flexible. In Python world I had to do a lot of setup to get that kind of thing going. Virtualenvs and pipemv and poetry weren’t terribly hard to configure but it took a lot more time to learn than PHP composer. Granted the ease of switching envs and versions in Python seems a lot simpler than PHP once it’s all setup.
- 7y ago
- oaiey 7y agoPHP has its appeal with a install and then run script situation. Its simplicity of lacking any "project" structure (like what node.js has with project.json and .NET has with .csproj) or more complicated setup (Python with setenv) makes the first days of teaching a lot easier. Also the 1:1 mapping of urls and files is appealing. However, after that first days, all of them rely on package managers (PHP, Node, Python, .NET, ...), custom routing and a structured project organization. This also explicit includes PHP. You should try .NET Core (in your scenario maybe with ASP.NET Core Razor Pages). Its setup is very easy (dotnet new webpage; dotnet run) and normal projects rarely need the package manager. The only challenge is the sub folder containing the web pages ;).
- tasogare 7y agoI’m using mainly ASP.net Core for my projects but PHP is still simpler to get started with IMO. Microsoft’s framework does a lot of things, and a lot of magic involved which means sometime searching for hours in doc and stack. Another difficult thing is Startup.cs and all the magic middlewares whose declaration order actually matter.
- oaiey 7y agoThat is right. And I agree. ASP.NET is already a framework on top. PHP is the best choice for immediate entry without explaining millions of concepts (like routing, middlewares, http, ...).
- lenlorijn 7y agoPHP uses composer as a package manager, which is quite simple to use and very easy to install (it's a phar archive, basically an executable zip file). And frameworks like Laravel can be installed with a single composer command. This is still very little setup to come to the same point.
- oaiey 7y agoThe problem an educator has is the time from start till first success (from early happiness but also time constraint perspective). In the first lecture. Important programming tools like Projects, Package Manager, Routing, separate view/model, ... are a delay in that timespan. They are all worth it and in most frameworks not too complicated. But each item needs time to explain.
- Aperocky 7y agoimo the best way to get started is html + js. And then write the backend in a backend language, flask is pretty good for beginners. Completely separate the concerns. PHP gets people all mixed up. Backend is for data and frontend is for display. And also, for most needs you don’t even need a backend. If your need is trivial, just get a lambda.
- Kwantuum 7y ago> for all other languages i know of, there is quite a process to get started It's funny that you included javascript in the list when you can literally just type javascript code in an html <script> tag and open it in the browser that comes with your OS. You quip at flask for requiring "command line experience" then talk about PHP's built-in web server that's also a command line tool. And let's be realistic, if you're using php without a package manager, you're either no doing anything serious or you're reinventing the wheel, and you will need to get comfortable with the command-line sooner or later anyway. I will say that PHP is probably the the most frictionless server-side web-development language to get started with, but it's not by a huge margin. And considering that in web-dev you're gonna need to learn javascript anyway, I'd probably consider it to be the best introductory language.
- travbrack 7y agoOr push three buttons from any webpage in Chrome and get a js console
- nkozyra 7y ago> It's funny that you included javascript in the list when you can literally just type javascript code in an html <script> tag and open it in the browser that comes with your OS. Let's be fair: you're going to be very limited in terms of the type of web site you can make with this approach compared with a PHP app via web server
- deleted 7y ago[deleted]
- collyw 7y agoIts a rather poor reason to choose a language in my opinion, but given the popularity of both PHP and JavaScript, one that has worked for many people.
- mettamage 7y ago> We have used, java, javascript, python and php for a basics course in webdev. Soooo...... How about Ruby on Rails?
- timw4mail 7y agoHas it gotten easier to actually get running, without resorting to a pre-built docker image? One of the biggest advantages of PHP is ease of actually doing the web server config, especially compared to dealing with an external app server along with its init script or systemd unit.
- ksec 7y agoRuby Rails doesn't even work work out of the box on Windows. Which makes teaching it 10x harder. ( US seems to be outliner in that every student is on MacBook )
- steve1977 7y agoPHP has built-in web features... or it's a web server with built-in programming features... ;)