5 ms·
What are valid reasons to use PHP? Like, you don't care about your code or you have no availability SLA?
by AsymetricCom 13y ago
What are valid reasons to use PHP? Like, you don't care about your code or you have no availability SLA?
- Joeri 13y agoIt's a great language for quick prototyping or doing sysadmin tasks (i would choose php over any shell script language any day). I also see no evidence that php apps in practice are any less reliable. Php is in fact probably more reliable because it doesn't give you dangerous stuff like multi-threading and because its very forgiving of errors (it doesn't consider an error a good reason to stop running code).
- yareally 13y agoAlthough it's not a feature that appeals to everyone, modern PHP (5.4+) has nearly any sort of syntactic/structural feature one would want in a programming language, except enumerations[0]. After using them in Scala, traits are also a nice plus to have in PHP. I do use PHP less than I used to, opting for Python more as it has more uses than PHP does (PHP can be used with GTK or CLI, but no thanks) outside of the web. There are also quite a few good libraries and frameworks out there for PHP, although they're hard to find if you're not already experienced in PHP and can filter out the horrible ones by reading their code. Compared to Python, the task of finding quality code is generally harder from all the existing stuff out there holding on to bad hacks from PHP 5.2 and before (as well as long time PHP developers abusing such bad hacks out of habit). Also, in PHP, trying to do anything event related with server to client notifications[1] comes down being an ugly hack[2] unless you want to use some third party PHP extensions like libevent[3] or offload to another language/service you could have just written everything in to begin with. PHP is just not built for anything unconventional like that and makes your life a headache if you ever find you need it at some point. Screwing with all of that is way more of a pain than just using Python with Tornado or Twisted, using Node.js or something like Play 2.0 with Scala. For what it's worth, the MySQLi native driver/api supports non-blocking async queries to the DB at least now and the native PostgreSQL API does as well (albeit the PgSQL API is not Object Oriented and I resorted to wrapping it a class that mimicked the MySQLi Object Oriented API for consistency). [0] http://marc.info/?t=132988607800003&r=1&w=3 http://marc.info/?t=132988607800003&r=1&w=3 (lots of futile rants about it here). Basically comes down someone rejecting enum because they claim it's "redundant" (though PHP has plenty of previously accepted redundancies) when you can fake them with classes (which is not true as you cannot use them in a switch [without faking with toString()] and cannot use them without instantiating an object). The other excuse is it would introduce "strict typing creep" to PHP, which is silly, since you can already type hint on functions by including a the class or array type in each parameter (and will even throw an error if using the incorrect type). Excuses are not surprising though, given the news the past month of how toxic the core developer mailing list is for PHP. [1] http://ajaxpatterns.org/HTTP_Streaming http://ajaxpatterns.org/HTTP_Streaming [2] To implement in PHP without event listeners, you have to use some sketchy third party php based http servers instead of fcgi+fpm for those parts or fake it with an infinite loop + sleep and use nginx + http push stream (http://wiki.nginx.org/HttpPushStreamModule http://wiki.nginx.org/HttpPushStreamModule) [3] http://php.net/manual/en/book.libevent.php http://php.net/manual/en/book.libevent.php
- tmzt 13y agoIf you want to use libevent/libev without coding the glue yourself, you can use React PHP (http://reactphp.org/ http://reactphp.org/), which supports timers, websocket/WAMP, ZeroMQ, HTTP (but not SSL), DNS, Redis (Predis async), and plain sockets. I'm using it for a project I'm working on because PHP has the only supported cpanel client library, and I don't want to maintain my own bindings for cpanel. I've found that React works quite well for processing queues in PHP and notifying the client via websocket when events occur. I did introduce a Play/Akka scheduling daemon instead of hand rolling that in React, which simplifies the PHP worker greatly as it only needs to process jobs submitted over ZMQ, not read the database and update an internal list of jobs. I would love to try porting this application to HHVM when there is support for a libev/libevent/libuv extension that is compatible with React. I was not aware of the async database library in PHP, though it doesn't seem to be integrated with the React main loop implementation and might be some work to get it working. Are you aware of the difference between Mysqli and Mysqlnd and do you know when I should use either on of them. (I use PDO for database access and prefer the OO api it provides.)
- yareally 13y agoHmm, I've heard of React, but have not had a chance to look at it much or use it yet. Looks like it would be better than any of the other alternatives out there though for PHP with a similar feature set. Thanks for the recommendation. MySQLnd uses the same API as MySQLi, so the only differences are deciding which to use within php.ini file and ability to use the asynchronous methods in for the MySQLi API in PHP. When MySQLnd originally came out, there was no support for SSL connections with it, but that's been fixed since PHP 5.4 I believe. Won't be able to use PDO though if wanting to use the async stuff (unless they have added that). Could probably write a small adapter to wrap one or the other though. MySQLi API design is kind of quirky compared to PDO API, so I generally write a small helper class to make life easier for dealing with prepared statements and binding variables to them.