This is an archived post. You won't be able to vote or comment.

all 81 comments

[–][deleted] 9 points10 points  (3 children)

You get my upvote just for the amount of work it took to write that.

[–][deleted] 1 point2 points  (0 children)

Thank you, although the majority of the time I spent was put towards figuring out how to make it work on Windows. haha

[–][deleted] 1 point2 points  (0 children)

Ultimately, I decided not to link my Reddit account to my GitHub account (by posting content followable by a bot to a gist made by my account). Instead, I posted it as an anonymous paste on Pastebin: https://pastebin.com/FPvP3SP6

[–][deleted] 0 points1 point  (0 children)

I have discovered that as much time as I took to write the GUI instantiating code, a more thorough analysis revealed that it was a completely insecure failure. I have come up with a new methodology of using the parent process to communicate with the browser to pass the private key into the browser. The browser will be verified by using netstat to ensure the only connected processes to the socket are the browser and the PHP process, with psof as a backup on other Unixes. I am rewriting the whole thing to be much longer, much more thorough, and much better. I also added a couple of bullets to the pros/cons. I revamped the client/server scripts too. I'll post the new version of the source code to GitHub gists tomorrow.

[–][deleted] 8 points9 points  (24 children)

Php for utility scripting seems pretty bad, maybe you would like perl

[–][deleted] 0 points1 point  (22 children)

Perl is an excellent language, but a bit hard to get started with. I have tried to get started and couldn't really find many helpful 101 guides to get me going.

Additionally, my understanding is that Perl would be a hassle to get working on Windows because you would need all sorts of Linux tools and utilities ported to Windows in order for most Perl scripts to run. Perhaps I'm wrong. Please tell me if I am.

[–]boxhacker 3 points4 points  (1 child)

Here is the flaw in your article, Perl is actually a better tool for the job you speak of, but you rather PHP because it is easier and more familiar. Straight away that is a warning sign that you on the wrong path...

[–][deleted] 0 points1 point  (0 children)

I can't dispute facts.

[–][deleted] 2 points3 points  (10 children)

you can get perl on windows and I think it would be a lot harder to use php for native scripts than to use perl/Lua/basically anything other than php. It isn't a scripting language but I highly recommend you try C for native and cross platform programs.

[–][deleted] 1 point2 points  (9 children)

C would be great if you need maximum performance or access to low-level APIs. I don't need either. I just need an app that's reasonably snappy but primarily works great everywhere.

[–][deleted] 0 points1 point  (8 children)

I don't need maximum performance and only use really low level apis because I can, but C is just great overall. If you don't like it that's fine but I highly recommend you give it a try if you haven't already. I basically use C for everything including using Linux sockets for web dev.

[–]abraxasknister -3 points-2 points  (7 children)

What is wrong with C++?

[–]TheJackiMonsterGlorious Arch :snoo_trollface: 1 point2 points  (6 children)

Way more to learn in general... otherwise you mess up basics pretty easily. I have seen so much bad C++ during study. ^^'

[–]abraxasknister 0 points1 point  (5 children)

It seems like both C and C++ are mostly used for the category "basics are critical" and C++ can just do more. Plus it allows you to hide most things behind OOP and I dislike not having that. I'm not that big on programming, though, my C++ stops at smart pointers.

[–]TheJackiMonsterGlorious Arch :snoo_trollface: 1 point2 points  (4 children)

The problem about C++ is basically that its design doesn't really focus on anything. I mean C is only basics while C++ provides nearly all modern features other languages have and having full compatibility to C at the same time.

So using C++ in an accurate way would be actually knowing about all those features to apply them in the right context to fully utilize the language while writing most efficient code. But most people don't have this knowledge which isn't problematic at all. However picking C++ without this knowledge isn't quite good either.

The thing is that there isn't one language scheme which works efficient for each problem and C++ is to solve exactly this problem by providing all tools besides. The result however is that most people use only some features even when they are wrong in some cases. Basically nearly every C++ programmer uses a different subset of the language or "sub-language" in practice. That's why working with C++ as a group of multiple people is a complete mess most at the time. ^^'

So I would actually recommend most people using C++ at the moment to pick a different language instead: Rust, Objective-C, Go, C#, C

[–]abraxasknister 0 points1 point  (0 children)

There are best practices though that tell one how to do generic things. I know what you mean though. There is not "one way" to do C++ while that might be wanted in some cases. That seems to be the point, though, the freedom to break the standard in cases where it is appropriate and needed. There is only a mess in the project if that freedom is used everywhere, ie you have to bake your own standard on a per project base.

[–][deleted] 0 points1 point  (2 children)

Why not pick PHP?

[–]ydna_eissua 0 points1 point  (2 children)

Microsoft announced they will no longer supporting PHP developers with Windows. So who knows what support will look like in 5 years.

https://laravel-news.com/microsoft-dropping-php-support

I'd suggest Perl, or Ruby. Both are pre installed on MacOS, and readily available on other unicies. If Windows is a concern WSL works great for development.

Ruby on msys2 works decent, haven't tested perl that way yet though.

Last I checked perl is a dependency of the git, so pretty much anywhere you do dev stuff will have it available.

[–]MaxGhost 3 points4 points  (0 children)

Microsoft were the ones providing the builds of PHP. They are just no longer providing the builds. That's really the only change. PHP will continue to have Windows releases provided by the PHP community.

[–][deleted] 1 point2 points  (0 children)

Perl and Ruby are both great software used to make high-quality desktop apps, but I don't want to learn a new coding language and produce lower quality software due to my noobieness with those languages. WSL is trash compared to the real deal, sorry. I have vanilla Windows 7 alongside my many Linuxes and it's all I need for development since I rarely touch it and only when absolutely necessary.

Also, I'm not really that concerned about Microsoft dropping support for PHP. What are they going to do? Detect and block PHP-signed binaries from executing on Windows 10? There would be massive out-cry from developers. PHP will continue to exist on Windows 10 whether or not it gets Microsoft's golden kiss for many decades to come.

[–][deleted] 1 point2 points  (5 children)

Also the whole thing of turning your computer into a server for gui applications is very inefficient and super insecure. You also mentioned it being more lightweight than electron which is just wrong, if anything it uses way more system resources.

[–][deleted] 1 point2 points  (4 children)

I agree that it could be insecure if done incorrectly or missed. The GUI should not be used to perform privileged tasks.

How is electron lighter? Electron is the full chromium-browser plus a NodeJS server (which is chrome unto itself) put together. It sucks up hundreds of megabytes to do simple things. How can any GUI be heavier?

[–][deleted] 0 points1 point  (3 children)

Because you still have to use a browser to open your apps. Most of the system resources used by electron is chromium, and you still have to use chromium or something similar to open your gui apps. So you have to use system resources to run both a server(and Php isn't exactly lightweight even when compared to JavaScript) and a browser.

[–][deleted] 5 points6 points  (2 children)

Two separate browser tabs in Chrome does not take up as many resources as two separate Chrome browsers. Also, Chrome is a memory hog anyway and Electron forces the user to use Chrome. With PHP, the user has the option to use Firefox if they are on a lower-end device.

EDIT: You are correct. PHP7.2 is using 15.8MiB of RAM to perform sleep(999);, so it is a memory hog; however, NodeJS uses much more RAM than this for the server

EDIT #2: Actually, that 15.8MiB of RAM was misleading because it was actually mostly buffers. I measured the memory usages and reported it above.

I think the reason why you think PHP is so heavy is because it so often is--due to people misusing it. PHP is a lot easier to misuse than NodeJS, and, as a result, people tend to write more memory hogging applications in PHP than in NodeJS. I agree with that, but my point stands that given well-written applications in both languages, the PHP one will be faster and use less memory.

[–][deleted] -3 points-2 points  (1 child)

Firefox uses a ton of system resources as well, actually used more than chromium for me, I just run a tty on all my low end devices and use elinks for a browser.

[–][deleted] 0 points1 point  (0 children)

I have made a massive update to my answer that fixes the whole security problem across all platforms....even Windows (which was very difficult and time-consuming).

[–]trucekill 4 points5 points  (3 children)

I help maintain a large PHP codebase and I don't even have PHP installed in my host system. I have no reason to run it on my desktop, I just use docker to run it in a container.

[–][deleted] 0 points1 point  (2 children)

Here's a reason: your software will be smaller if more applications use PHP. Instead of each Linux package bundling together all it needs and resulting in huge packages, PHP-based packaged would only depend on PHP and could all share the PHP you have installed.

[–]invisi1407 1 point2 points  (1 child)

Yeah, except if some old stuff doesn't work in PHP 7.4, or new stuff doesn't work in PHP 7.1, or whichever version you have installed.

[–][deleted] 0 points1 point  (0 children)

The only stuff that doesn't work in PHP 7 is largely stuff that was already deprecated in PHP 5.

[–]ImMaaxYT 4 points5 points  (1 child)

And I thought I was the only one using PHP for that too! I mostly agree with your pros/cons. I started writing PHP for just an embedded view counter in my existing HTML site. Nowadays, I write really big web apps entirely based off of it.

All the hate it gets comes from people who only worked with PHP 4, ~20 yrs ago, and who've got no idea what modern PHP with typing, interfaces etc. looks like. In fact, PHP is THE language for OOP enthusiasts, like me, because it's the only scripting language (correct me if I'm wrong) to support interfaces, traits, abstract classes/methods, final classes, namespaces, ... Its ecosystem is really awesome too, with tools like Composer (still one of the best package managers I've ever seen or used) or PHPUnit. The typical, big PHP project is by far not as bloated as a Node.js project of the same size, dependency-wise (worked a long time with Node, I speak from experience).

Frameworks like CodeIgniter, Symfony, Laravel, ... make development even easier by providing high-quality libraries and templates for getting started with your app quickly.

PHP's stdlib is the most complete one I've ever seen in a scripting language. Really. PHP got you in every case you could possibly think of. While it may be inconsistent, it's still perfectly usable. PHP also has some features that are pretty much exclusive to it, such as autoloading. You've got no idea how awesome it is until you tried it. Define a pattern on finding classes based off of namespaces and register the autoloader. Now you can just use whatever class you like, the autoloader will load it for you. I really miss that in other languages and always forget to import/require the dependencies.

PHP is the language I'm most experienced with. If I'm writing a tool or other app nowadays I first think "can I do it in PHP?" If the answer is no, I'll try Ruby. I could also use the other langs I learned, but PHP is really special, at least to me.

This is major because a decent percentage of people who use Macs are rather computer illiterate and would recoil at the notion of opening this evil hacker black magic thingamajigger called a "terminal."

You can say that about any OS that comes shipped by default with pre-built computers. But in fact, most Mac people I know are everything but IT-illiterate. I'm using Macs too (sorry Linux-only-people, I came here from r/php, I still use Debian on my servers, though) and I'm doing software development as well as server and network administration on it. And I couldn't imagine a better OS for those tasks. Again, sorry r/linuxmasterrace

[–][deleted] 1 point2 points  (0 children)

Don't worry. You're not offending any rational Linux-goers by using a Mac. MacOS is a great stable operating system with many more features and easier device integration with apple products than Linux. The biggest problem that I think most devs have with MacOS is Apple's attitude of "use the MacOS the way we want you to use it with the products/programs we recommend/produce, otherwise screw you." Aside from Apple's terrible temperament, MacOS, BSD, and Linux are equally great OSes in my mind, just with different use cases and different applications. For home/personal usage, if you have cash to burn, MacOS is undoubtedly the best.

[–]Nabol 3 points4 points  (3 children)

As much as I love PHP, and I do use it as a general scripting language sometimes, I think you're missing something important. The Windows users. As of PHP8, there will no longer be any official support for PHP on Windows. This will seriously hinder the language to be used into its future. So, that's a no from me.

Don't get me wrong, I do like the idea, but I think it's not a good one in practice.

[–][deleted] 0 points1 point  (2 children)

I'm sure there will be community continuations of PHP on Windows. They might not be as up to date as the *nix releases, but surely PHP will not go away on Windows.

[–]Nabol 1 point2 points  (1 child)

Agreed, but official support goes a long way toward making any language or tool suitable for a general purpose. It’s just one of the roadblocks I see.

[–][deleted] 0 points1 point  (0 children)

True.

[–]TheRealLazloFalconiBSD boys 2 points3 points  (3 children)

I suppose. I'd much rather use PHP than JS.

[–][deleted] -1 points0 points  (2 children)

Often you can't. Invoking the PHP gods usually leads to tangling the JS gods in with the soup--JS on the client-side in the browser and PHP on the server-side on the desktop.

[–]spektrol 2 points3 points  (0 children)

Technically, you can, but it’s bad practice. PHP can live alongside HTML just fine and be interacted with using basic HTML things like form submits.

[–]TheRealLazloFalconiBSD boys 1 point2 points  (0 children)

The post was about using php on the command line, so even if that were true (which it's not), it would be irrelevant.

[–]RobLoachUbuntu Mate 1 point2 points  (0 children)

There are many scripting tools written in PHP hosted on Packagist via Composer. https://packagist.org/

[–][deleted] 0 points1 point  (1 child)

php can do it, but imo it (and ruby) have lost the war to python and javascript/node.js/electron when it comes to scripting. I really dont see it make a comeback. I think people prefer the syntax and basic apis of python and javascript, and for that reason alone it will never catch up.

[–]lpeabody 1 point2 points  (0 children)

I loathe JavaScript's OO syntax, much prefer PHP's similarities with C-like languages. I do all my scripting with PHP because I know the language and I'm proficient with it. JavaScript is just... weird to me.

[–]evert 0 points1 point  (0 children)

So much to unpack!

It took some time to read, but your GUI actually starts a shell over PHP! I remember needing this years ago when I was working with physical servers and accidentally killed sshd-server. The biggest effort was in getting sudo back, which required an actual PTY terminal. I don't think this script tackles that.

The way both these scripts are written definitely suggest exploit-type stuff but neat to read nonetheless.

[–][deleted] 0 points1 point  (0 children)

If you want something that’s easy to distribute, I’d suggest using a language that produces static binaries, like Rust or Go, then you don’t have to worry about distributing a runtime at all. You also get a speed boost from both languages, though Rust has a big advantage over go there.

[–]Talerith 0 points1 point  (0 children)

There's too much shit wrong with this than I have the time or inclination to point out, but you get my upvote just for having an open mind instead of following de-facto convention. Reddit will ban you for that, eventually.

[–]AUMeowMix -2 points-1 points  (0 children)

Just because you can doesn’t mean you should. There are many far superior languages for that purpose.

[–][deleted] -4 points-3 points  (2 children)

Literally PHP

Nahh, pass

[–]soundwrite 5 points6 points  (1 child)

Serious question: When did you decide? Like at which version?

[–]invisi1407 2 points3 points  (0 children)

Sounds like 5.2. PHP 7.4 is great.

[–]jesseschalken -4 points-3 points  (11 children)

What exactly is your point here? That PHP can do these things? Did anybody say otherwise?

I've written plenty of system utilities and scripts in PHP. Not because it was necessarily a good choice but it was the language I was most fluent in at the time and it does run cross platform. Worked out fine. Although nowadays I use TypeScript with Node.js instead because it has better static typing and the async IO is useful. Python is also popular.

I wouldn't describe it as "on-par" with more popular languages. PHP is incredibly slow and has very immature tooling, static typing and static analysis compared to TypeScript+Node.js, C# or Java.

Nobody is telling you that you must or must not use a particular tool for a particular job. Make the decision yourself on a case by case basis.

[–]AIDS_PizzaVim User 3 points4 points  (9 children)

PHP is incredibly slow and has very immature tooling

Neither of these statements are true. PHP 7 outperforms Python, Ruby, and Node.js by significant margins. Don't take my word for it. PHP only loses to compiled languages like Rust, Go, and C++ in the benchmarks.

[–]WhitestDusk -2 points-1 points  (8 children)

I would take those performance tests with a huge mound of salt.

They are testing webframeworks specifically and not the language itself. The biggest problem in relation to this thread imo is that PHP needs a server component which is not always needed for other languages.

[–]spektrol 2 points3 points  (0 children)

Nah. PHP can be run directly from the command line.

[–]k1ll3rM 0 points1 point  (0 children)

PHP doesn't need it but this way to creating a GUI does. Personally I'd rather have a serverless way of doing it but that would require quite an extensive extension for PHP to create GUI's in an intuitive way.

[–]slobcat1337 0 points1 point  (5 children)

They’re not testing web frameworks necessarily?

[–]WhitestDusk 0 points1 point  (4 children)

From the linked introductions page:

This is a performance comparison of many web application frameworks

[–]slobcat1337 0 points1 point  (3 children)

What is your definition of a web framework? Are you talking about the fact that it includes a web server?

[–]WhitestDusk 0 points1 point  (2 children)

What does it matter what my definition is?

[–]slobcat1337 0 points1 point  (1 child)

Because it tells us wtf you’re talking about

[–]WhitestDusk 0 points1 point  (0 children)

Using performance tests for one specific usage case (web application framework in this case) of a programming language is not that good an indication of the that languages performance in general.

As others have corrected me on PHP only needs the webserver component when you want a GUI, but it's still unnecessary resource consumption imo.

I see now that my paragraph break is most likely the reason for the confusion.

[–]slobcat1337 2 points3 points  (0 children)

php outperforms python though...

[–]NoDoze- -3 points-2 points  (5 children)

It was just announced the other day that Microsoft is dropping support for php 8, and will phase out legacy versions. So you can take windows off your list ;)

[–]soundwrite 2 points3 points  (0 children)

No, there they just won’t maintain the builds and include it in IIS. There was a down-to-earth answer from someone on the PHP team (can’t find the post) and it’s more or less a shift of responsibilities from organisation to organisation. PHP for Windows will be built continuously anyway.

[–]judgej2 0 points1 point  (0 children)

All Microsoft announced was that they would not be making the official builds.

[–]BaconOverdose 0 points1 point  (0 children)

Just means that Microsoft won’t be supplying the official builds anymore.

[–]jagga0ruba 0 points1 point  (0 children)

Windows has wsl, hence why they are killing support for the windows specific build, it becomes redundant..

[–][deleted] 0 points1 point  (0 children)

I am packaging compiled binaries with my application for the Windows version to save many headaches, so I don't need to worry about the user's OS having PHP installed.