phar vs WAR

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

phar vs WAR

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

I was just checking the doc - creating a phar is not as easy as using java's jar tool to pack.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
Post Reply