Move to php in windows? Concern, hints, "please don't do!"? - php

I am considering to move frome Microsoft languages to PHP (just for web dev) which has quite an interesting syntax, a perlish look (but a wider programmer base) and it allows me to reuse the web without reinventing it. I have some concerns too. I would be more than happy to gather some wisdom from stackoverflow community, (challenge to my opinions warmly welcome). Here are my doubts about using PHP on IIS web server on windows server .
Efficiency. Cgi are slow, what I am supposed to use? Fastcgi? Or what else?
Efficiency + stability. Is PHP on windows really stable and a good choice in terms of performances?
Database. I use very often MSSQL (I regret, i like it). Could I widely and efficiently interface PHP with MSSQL (using smartly stored pro, for example).
XSLT + XML performance. I work quite a lot with XML and XSLT and I really find the MS xml parser a great software component. Are parser used in PHP fast, reliable and efficient (I am interested mainly in DOM, not SAX)?
Objects. Is the PHP object programming model valid end efficient?
6 Regex. How efficient is PHP processing regexp?
Many thanks for your advices.

Efficiency. Cgi are slow, what I am supposed to use? Fastcgi? Or what else?
PHP runs as Apache module so there is no need for FastCGI.
Efficiency + stability. Is PHP on windows really stable and a good choice in terms of performances?
Personally i wouldn't use PHP on Windows but my experience shows that there is no big difference to Linux & PHP
Database. I use very often MSSQL (I regret, i like it). Could I widely and efficiently interface PHP with MSSQL (using smartly stored pro, for example).
PHP can access MSSQL via ODBC or via the native MSSQL extension. You might want to look into PostgreSQL though.
XSLT + XML performance. I work quite a lot with XML and XSLT and I really find the MS xml parser a great software component. Are parser used in PHP fast, reliable and efficient (I am interested mainly in DOM, not SAX)?
No experience there, sorry.
Objects. Is the PHP object programming model valid end efficient?
Since PHP 5 (especially 5.3) Object oriented programming in PHP is acceptable. It supports everything most other languages support, inheritance, interfaces, overloading, ...
Regex. How efficient is PHP processing regexp?
PHP uses the PCRE library afair so there shouldn't be much difference to other languages.
All in all:
I'm no fan of PHP, i greatly prefer languages with strong types like C/C++/C#/Java but for a scripting language PHP made huge improvements to the PHP we knew a few years ago. If you stick to object oriented programming PHP can be a clean and good language. The main drawback is:
PHP has no object oriented base, i.e. no string class, it uses C-like functions (strchr, strstr, strlen, ...), this makes OOP harder, you have to have more discipline to develop good code.

You should also consider cost. PHP + MySQL doesn't cost big money like building on top of a Microsoft stack (Asp.net + SQL Server + Windows Server). Hello licensing fees!

If you are doing PHP and considering MySQL you might as well be on a LAMP stack.

That depends on which web server you are using (or want to use). In Apache you can embed PHP as a module, which is faster than CGI. I'm not sure whether this can be done with IIS too.
I have been using PHP on Windows for about 6 years now, it has never crashed; of course there are the usual infinite loops, but restarting the web server is always sufficient. Also, the efficiency and stability are more related to the web server than to the operating system.
Yes, see: http://nl2.php.net/mssql
For DOM there is: http://php.net/manual/en/book.dom.php I don't know how it compares in performance with other XML parsers, I mainly use the SimpleXML http://nl3.php.net/simplexml parser. XSLT is a bit outdated in PHP, it only supports version 1.0: http://nl2.php.net/manual/en/book.xslt.php
PHP has a good Object Oriented programming model; it supports classes, interfaces, statics, exceptions, reflection, etc. But as it is a scripting language it lacks strong typing.
See: http://nl3.php.net/manual/en/ref.pcre.php

In answer to question 3 - yes, you can easily connect to mssql dbs using PHP. Read more in the PHP manual - http://php.net/manual/en/ref.mssql.php or use an abstraction layer like Pear::MDB2 - http://pear.php.net/manual/en/package.database.mdb2.intro.php

Related

What's a good non-web application development environment for someone comfortable with PHP/Javascript/Mysql?

I would like to be able to write database driven applications (i.e. standalone apps that are not web based and don't require a browser or Apache server to run)
I have attempted to do this in Codegear C++ Builder in the past but even though my 'background' is in that (C++ OOP with Borland Builder) it is so far removed from doing the same sort of thing with PHP/mysql and other web technologies that I found that I couldn't get very far for a lot of effort getting it to work. It was a while ago now but I was using the built-in database engine that comes with Builder and I just found it frustrating and difficult.
In other words - Is there something out there that will allow me to make use of web based languages to write standalone applications (specifically PHP/Javascript/mysql)
You can stick with PHP if you want. There are QT bindings, GTK bindings, OSX/Cocoa bindings, and you can call Win32 functions. I don't know how stable all of those are, but you can do GUI in PHP as well as the command line stuff.
As for other languages... PHP is very C like. It started as basically a scripting wrapper around C (IIRC), which is why you have functions named after the C standard library (like strstr). C like languages will feel quite familiar.
I would think Python would probably be the closest to PHP. It's a scripting language, syntax is somewhat close, it has a ton of libraries, and is very well supported and commonly used. I'd imagine it would feel pretty familiar. Using indenting instead of brackets for blocks can throw some people, but it fit the way I already indented my code.
Ruby is quite popular, and is also a scripting language. I think it's farther away, syntax wise, than Python, but I've never really used it so I can't promise that. I know it has at least GTK bindings.
Perl has a lot of resources and bindings, but isn't as easy to read as PHP since you have to learn the special variables like #_. It was never really my cup of tea.
You do have the C/C++ stuff, and Java has it's large library. You may want to go that way since you say you've used C++ before. If you're on a Mac (or willing to use GNUStep) you could go with Objective-C/Cocoa. That's getting rather far from PHP syntax though.
All of these languages have database connections. You don't mention what platform you're on.
But for easy to work with, quick to pick up, works all sorts of places, and can definitely do GUIs... Python would be a good choice to look at.
You could always use PHP. It is a decent command-line / programing application. Other than that all I can say is that you knowledge of database access and storage will be helpful but by the end of the day you are going to need to learn a new language.
Most languages have libraries for database access. Just pick one that you like the feel of. It is also a good idea to choose one that is popular (for the community support) and free libraries are always nice. Also look for good documentation and one that is fairly standard.
A nice thing to know is that javascript and php syntax are very similar to many other languages. (Javascript looks almost identical to C and C++). Just read the main language tutorial then the database API tutorial and you should be good to go

Best server-side language for MySQL and PHP

So I have access to a dedicated server and want to finally create my game - it's a browser based game, fairly simple. I know PHP and MySQL fairly well and would want to integrate with them on the front end.
The question is what is a good server-side language to use either as a constant process or with cron to interface with the MySQL database to do calculations?
Ideally my requirements are:
As short a learning curve as
possible.
Easiest access to MySQL as
possible.
As hard to shoot yourself
in the foot as possible.
I'd like to avoid C/C++ if possible for the above 'shoot yourself in the foot' problems. It'd also be nice to have a secondary language to use personally so I may take it beyond this limited scope.
Thanks in advance for any insights!
You could use commandline php with cron. The great advantage of that is that you can reuse libraries that you write for your game and you already know the language. I don't think it's performance is great though.
Besides that there are a ton of languages you might choose, Python and Java are popular.
There are two good options here:
PHP
PHP is a server side language, and if you design the frontend with some robust classes, you can reuse the classes for the command-line daemon. This allows you to have a more standardized application suite, which will be easier to modify in the future. PHP can access MySQL, and since you already know it, the learning curve will be minimal.
Python
Python is an excellent server side language for an application like this. It can talk to any SQL database with a standardized instruction set, called DB API 2.0. This means taht if at any point you want to change from MySQL to PostgresSQL, you simple change:
import my_mysql_library as sql
to:
import my_postgres_library as sql
And your application won't need any other code changes. Python also contains many libraries that might come in handy, and if optimized correctly, will be faster than PHP.
Conclusion
Personally, I would use Python, for the following reasons:
Learning Experience; Programming is always about learning. At any opportunity, use a language or tool you don't already know so that you can learn it.
Language Preference; After programming in both PHP and Python, I can honestly say that there is no situation where I would prefer to use PHP over Python. Not one.
Available Libraries; Python has a very robust community, and a lot of useful libraries and packages (such as NumPy) that make things much easier for you.
With both languages you could have them run intermittently via a cron job, or you could have them run as a Daemon (which is as easy as running the script(s) while piping your output to a black hole, such as /dev/null)
Another great option for your server side scripting is perl. It has a bit of a learning curve at the start but becomes a very fast language to script in.
A great resource is http://perldoc.perl.org/

What makes PHP slower than Java or C#?

This is something I've always wondered: Why is PHP slower than Java or C#, if all 3 of these languages get compiled down to bytecode and then executed from there? I know that normally PHP recompiles each file with each request, but even when you bring APC (a bytecode cache) into the picture, the performance is nowhere near that of Java or C# (although APC greatly improves it).
Edit:
I'm not even talking about these languages on the web level. I am talking about the comparison of them when they're number crunching. Not even including startup time or anything like that.
Also, I am not making some kind of decision based on the replies here. PHP is my language of choice; I was simply curious about its design.
One reason is the lack of a JIT compiler in PHP, as others have mentioned.
Another big reason is PHP's dynamic typing. A dynamically typed language is always going to be slower than a statically typed language, because variable types are checked at run-time instead of compile-time. As a result, statically typed languages like C# and Java are going to be significantly faster at run-time, though they typically have to be compiled ahead of time. A JIT compiler makes this less of an issue for dynamically typed languages, but alas, PHP does not have one built-in. (Edit: PHP 8 will come with a built-in JIT compiler.)
I'm guessing you are a little bit into the comparing of apples and oranges here - assuming that you are using all these languages to create web applications there is quite a bit more to it than just the language. (And lots of the time it is the database that is slowing you down ;-)
I would never suggest choosing one of these languages over the other on the basis of a speed argument.
Both Java and C# have JIT compilers, which take the bytecode and compile into true machine code. The act of compiling it can take time, hence C# and Java can suffer from slower startup times, but once the code is JIT compiled, its performance is in the same ballpark as any "truly compiled" language like C++.
The biggest single reason is that Java's HotSpot JVM and C#'s CLR both use Just-In-Time (JIT) compilation. JIT compilation compiles the bytecodes down to native code that runs directly on the processor.
Also I think Java bytecode and CIL are lower-level than PHP's internal bytecode which might make alot of JIT optimizations easier and more effective.
A wild guess might be that JAVA depends on some kind of "application" server, while PHP doesn't -- which means a new environnement has to be created each time a PHP page is called.
(This was especially true when PHP was/is used as a CGI, and not as an Apache module or via FastCGI)
Another idea might be that C# and JAVA compilers can do some heavy optimisations at compile time -- on the other side, as PHP scripts are compiled (at least, if you don't "cheat" with an opcode cache) each time a page is called, the compilation phase has to be real quick ; which means it's not possible to spend much time optimizing.
Still : Each version of PHP generally comes with some amelioration of the performances ; for instance, you can gain between 15% and 25% of CPU, when switching from PHP 5.2 to 5.3.
For instance, take a look at those benchmarks :
Benchmark of PHP Branches 3.0 through 5.3-CVS
Performance PHP 5.2 vs PHP 5.3 - huge gain
Bench PHP 5.2 vs PHP 5.3 -- disclaimer : it's in french, and I'm the one who did it.
One important thing, also, is that PHP is quite easy to scale : just add a couple of web servers, and voila !
The problem you often meet when going from 1 to several servers is with sessions -- store those in DB or memcached (very easy), and problem solved !
As a sidenote : I would not recommend choosing a technology because there is a couple of percent difference of speed on some benchmark : there are far more important factors, like how well your team know each technology -- or, even, the algorithms you are going to use !
There is no way an interpreted language can be faster than a compiled language or even a JIT language under trivial conditions.
Unless your test program consists of printing out "Hello Worlds" if you are concerned about speed, stick with C# or Java.
Depends on what you want to do. In some cases, PHP is definitely faster. PHP is (pretty) good at file manipulation and other basic stuff (also XML stuff). Java or C# might be slower in those cases (though I didn't benchmark).
Also, the PHP output (HTML or whatever) needs to be downloaded to the browser, which also consumes time.
Also, the speed of Java / C# is very much depending on the machine it runs on (which could be multiple). Java / C# could be slow on your computer, while PHP just runs on one server from which it is available and is always as fast as the server is (except for download times, etc.).
I don't think they are comparable in a general manner. I think you need to take a task, which you could be accomplished with those three programming languages, and then compare that. That is basically always what you should do when choosing a programming language; find the one that fits the task. Don't shape the task until it fits the programming language.
According to wikipedia, PHP uses The Zend Engine, which does not have a JIT.

What challenges will we face porting a site from asp.net to a LAMP (php) stack?

We have an enterprise application written in asp.net c# (3.5) and SQL server that we want to bundle and release for customers.
However, several have expressed concerns that it requires a Microsoft server due to the costs. Yes, I know... Therefore, we are considering porting it to a LAMP stack, with the "P" referring to php.
What challenges can we expect to face developing on a LAMP stack coming from a Visual Studio asp.net environment?
The issues I am sure of are:
Debugging: Visual Studio is awesome for both client and server side debugging.
Framework: The code behind model works great, and the MVC framework is nice.
Maintenance: We would like the feature set to be common on both platforms.
Database layer: Code is loosely coupled to the mssql data types.
If you've been through this exciting process, I'd love to know what it was like with some recommendations/tips.
As a side to this, is there any way for us to run this code as is? Mono? Others?
Another PHP IDE that you can consider is NetBeans.
As a .NET, Java, and LAMP developer at one point or another, the biggest change was largely cultural. For example, PHP has a legacy of not using OO principles whereas ASP .NET started off as a .NET language with full OO support. This basic difference leads to significant issues such as PHP's long lists of reserved keywords and so forth.
Other MVC frameworks:
CodeIgniter
Kohana
Yii
(Just found out about Yii. Here's an article that compares them.)
There are probably a half-dozen more out there, as well.
I have more experience with .NET than the *AMP stacks, but based on my experience with XAMPP, I would offer the following observations
Debugging: Visual Studio is awesome for both client and server side debugging.
Eclipse PDT works great for design, development, and debugging. I've heard good things about Zend Studio but haven't worked with it.
Framework: The code behind model works great, and the MVC framework is nice.
There are frameworks to allow you to separate presentation from logic (e.g. Smarty ) and at least one MVC framework is available (e.g. CakePHP)
Maintenance: We would like the feature set to be common on both platforms.
If you exclude Windows specific functionality (Windows Integrated Security, etc) there shouldn't be much you can't do in both stacks, but if you have to reproduce controls like the gridview it will be labor intensive.
Database layer: Code is loosely coupled to the mssql data types.
I am not aware of any data types that cannot be mapped between mysql and sql server and there is good documentation for handling migrations
Mono might decrease the amount of time required to port your solution, but I am unaware of any way you could re-use all of your code "as is".
i have a Asp.net background myself and have been researching open source frameworks for the last few months. I still haven't made up my mind. I've recently been looking at Grails. Seems to have the best of both worlds - a scripted, easy to use, open source RAD MVC framework on an enterprise platform. It uses the Groovy scripting language (ruby -like) but runs on the JVM so you can use full Java framework if you like. there's tons of prewritten java components out there to tap into. This thing is pretty cool. you'd be able to port your existing app pretty quickly. You'll need a Tomcat webhost though.
if you need PHP, straight PHP performs pretty well but most of the frameworks are poor performers. If go with straight PHP there's no mvc. You'd be using the traditional page based model. But you'll feel more at home. You can roll your own DAL with PDO and use stored procedures. You'll need a templating system though. Stay away from Smarty which uses it's own templating language. It's slow and why do you need to learn a seprate templating language. i never got that. Use Savant instead: http://phpsavant.com/. it uses php for template language and is fast. You can mimick code-behind with this too by creating a template page for each site page. As far as mvc there's a new PHP framework called Yii (http://www.yiiframework.com/) that claims to have the best performance out there for php frameworks. It's well documented too. It's probably the best the php framework out there if you're coming from .Net. Feels enterprisey like Zend but without the poor performance. Most of the others are toy-ish or really slow like Symphony and Cake. Php works great with Apache. Not a lot of tuning or maintenance unlike Rails and Django.
Next you need an IDE. Go with Netbeans. Use the PHP version and install http://www.xdebug.org/. Will feel inferior to VS but it's not bad.
For a DB, MySql is the sexy pick but Postgres is superior. It has one db engine that does it all. With Mysql, some features you want are in InnoDB and some are in MyIsam. If you need foreign keys and transactions you have to use InnoDB. Use MyIsam for fulltext search and faster read performance. Postgres performance has greatly imnproved with the version 8 release (same as mysql now) and has a nice windows installer finally.

Does a PHP Generator Framework or reference exist?

Back in the scripted ASP and ColdFusion days, I used to work on projects that would build code generators for ASP or Coldfusion, typically in C++, in order to be more object oriented in application design and not have developers writing scripted code, which often was called "spaghetti code" for it's size and complexity.
Since I've been coding asp.net since 2000, I haven't really had to deal with the issue at all, since the platform is not scripted.
I may be working on PHP projects in the future, and I was wondering if any code generators for PHP exist, or if any good references for building these generators exist.
It would be for the Linux platform, not targeted to Win2008 Servers running PHP.
Why not just build a proper app in PHP instead of going through the hassle? Recent PHP is fully object-oriented and lets you do some pretty decent stuff. There are even frameworks that help you do this kind of stuff.
I'm rather sceptical on the merits of code generation in the context of a dynamic language, such as PHP. You can generally use other kinds of abstraction to get the same results. Unlike a statically typed, compiled language, it is rather easy to use dynamic hooks such as __get and __set and reflection, to make generic abstract objects.
It's better that you learned good development practices in PHP than use code-generators. PHP might be a scripting language but it is quite potent, has a nice OO model, plenty of good frameworks and other open-source packages.
It's up to the developer to create well designed and factored code base, regardless of whether it's compiled at run-time or not.

Categories