Page 1 of 1
phar vs WAR
Posted: Thu May 17, 2007 6:57 am
by anjanesh
Hi
I was chatting with my friend who is into Java/J2EE and I learnt that WAR files is the only way of deployment of a Java web-app. Theres no way to FTP-upload an individual JSP page and run it like the way we can in PHP. I thought this is was a little weird as, for every minor correction, we go to remake the entire WAR file and upload it.
But it seems that php has now brought in that option too (since 5.2.0) by using
phar ?
If code can be encrypted or something it would make sense. WAR files have class files, if phar is going to have php source files, then what the use if this ?
Thanks
Posted: Thu May 17, 2007 7:17 am
by Chris Corbyn
I'm glad you pointed to that page since I wasn't aware of it and have been looking for something like this
It just makes it easier to provide bundles of classes (like a library) in a single file which the developer can manage a lot easier than loads of smaller files.
As for the WAR/JAR stuff for Java, that's not true. You can simply provide manifest information from /WEB-INF/web.xml. It's more fiddly making changes to a Java application over the web since the source first needs to be compiled into JVM code though.
Posted: Sun Jul 15, 2007 8:38 am
by anjanesh
I would love to see SwiftMailer as a single .phar file - should make a lot of things easier when it comes to uploading.
Posted: Sun Jul 15, 2007 8:53 am
by Chris Corbyn
I thought about it but it looked a little pointless when I came to think about it. The big help with JAR/WAR files is that they contains all environment information. PHP doesn't really need this sort of configuration to run correctly. The phar:// stream looks a bit silly too since you still need to know where things are in the archive and then delcare subsequent includes. If it registered class locations for autoloading or something it would be more worthwhile. Something like:
Code: Select all
phar_import("file:///foo/bar/swift.phar");
$swift = new Swift(new Swift_Connection_SMTP(...));
//No need for further includes
Posted: Sun Jul 15, 2007 9:51 am
by anjanesh
True, but I guess more people (esp startup business oriented who have little tech knowledge) will begin to use since it would be easier for them.
The only way it can be done is using some load.php which'll have all the required require_once statements.
Posted: Sun Jul 15, 2007 10:16 am
by Chris Corbyn
anjanesh wrote:True, but I guess more people (esp startup business oriented who have little tech knowledge) will begin to use since it would be easier for them.
The only way it can be done is using some load.php which'll have all the required require_once statements.
In PHP >=5.1 you could simply have the phar file load in a spl_autoload_register() call to do what I wanted. I'll look into it again and see how quick of a job it will be to bundle up phar files as part of my packaging routine.
Posted: Sun Jul 15, 2007 11:29 am
by anjanesh
I was just checking the doc - creating a phar is not as easy as using java's jar tool to pack.
Posted: Sun Jul 15, 2007 11:32 am
by Chris Corbyn
anjanesh wrote:I was just checking the doc - creating a phar is not as easy as using java's jar tool to pack.
I know, it's peculiar. You need to use a PHP script to do the packing. ZIP format archives would make things heaps easier.