TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Combining Golang and PHP can solve real-world development challenges

70 pointsby dhotsonover 6 years ago

15 comments

osrecover 6 years ago
I think the standard PHP model (one process per request), while still popular, is being replaced with fairly robust event loops. I&#x27;ve been using Swoole (<a href="https:&#x2F;&#x2F;github.com&#x2F;swoole&#x2F;swoole-src" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;swoole&#x2F;swoole-src</a>) in my company for about a year now, and it has matured into quite a stable code base, even if the documentation is lacking at times. The performance is pretty phenomenal and it has useful async coroutines for interacting with redis&#x2F;MySQL&#x2F;PgSQL. I saw some benchmarks in their GitHub issues list where it outperformed Node and Go (taken with a pinch of salt obviously).<p>If you&#x27;re afraid of something as experimental as Swoole, more stable options do exist, such as ReactPHP. Not quite as performant apparently, but seem to be popular.<p>In general, I find that the PHP ecosystem is still thriving. It&#x27;s definitely one of the easier languages to get up and running with, and now thanks to the community, it&#x27;s imbibing some of the more advanced features found in more modern languages.<p>I still love PHP, as much as the 10 year old me did when I started using it 20 years ago. It just gets the job done, even if it is a bit ugly at times!
评论 #18657347 未加载
nolokover 6 years ago
&gt; we can no longer use f5-debug<p>Sums up what is still one of the major issue-slash-weirdness of the php dev world. For all the frameworks and language advance, despite xdebug existing for over 15 years and working great in pretty much any editor or IDE, most PHP dev including the &quot;experienced&quot; ones have no idea how to use a debugger, or if they do they don&#x27;t apply it to PHP.<p>Can you imagine debugging your C&#x2F;C++&#x2F;Rust&#x2F;Go&#x2F;... programs by adding printf everywhere and re-run the whole thing ? Again and again to find which variable fail; while a simple step by step with watches would solve it in a single run, in a tenth of the time, without needing to crappify the source ? That&#x27;s what 99% of PHP dev still do.<p>Even the javascript world have adopted proper debugger right in the browser. But in PHP it&#x27;s so freaking terrible that when people need to solve a bug you don&#x27;t hear &quot;step until you spot the issue&quot; but &quot;var_dump all the things&quot; or &quot;log to the symfony debug bar !&quot;.
评论 #18651285 未加载
评论 #18651318 未加载
评论 #18651501 未加载
评论 #18651487 未加载
评论 #18651288 未加载
评论 #18652349 未加载
评论 #18651289 未加载
评论 #18652470 未加载
评论 #18651283 未加载
评论 #18651218 未加载
评论 #18652853 未加载
评论 #18651613 未加载
评论 #18651882 未加载
stabblesover 6 years ago
If the goal is to save resources, maybe it&#x27;s worth switching to Go entirely.<p>It&#x27;s a shame the article does not explain what was unsatisfactory about php-pm [1], which is a native php solution that also allows the application to boot just once for all requests.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;php-pm&#x2F;php-pm" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;php-pm&#x2F;php-pm</a>
评论 #18651528 未加载
评论 #18651124 未加载
flashmobover 6 years ago
I&#x27;m also one of those who switched from PHP to Go and now I have quite a bit of legacy PHP code that just works and don&#x27;t have time to rewrite.<p>My solution:<p>Use a Go FastCGI client library to call PHP by talking directly to php-fpm. It saves on the HTTP request overhead and no need to run a web server. Actually, php-fpm is a decent application server itself.<p>Edit: Here&#x27;s a link to example code: <a href="https:&#x2F;&#x2F;github.com&#x2F;tomasen&#x2F;fcgi_client" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tomasen&#x2F;fcgi_client</a>
toast0over 6 years ago
This probably works ok, but it&#x27;s doubling down on the terrible that is modern php. PHP has this wonderful conceptual model of get a request, return a response, and throw everything away. The logical consequence is that everything you built up in objects or variables along the way of making your response is garbage (because you&#x27;re throwing it away when you&#x27;re done).<p>Since you&#x27;re just making garbage, it doesn&#x27;t need to be pretty, it just needs to be fast.<p>Since you&#x27;re making garbage, it doesn&#x27;t need to be future proof, it will only be alive for 10ms.<p>You can make some really fast pages with PHP if you try, but modern frameworks are going to take longer to load than a fast page will take to be finished.
furicaneover 6 years ago
40x speedup claim with 0 evidence or reproduction scenario. It&#x27;s like that meme: &quot;source: trust me dude&quot;. The conclusionnis: they made a middleware, something that nginx&#x27;s auth module does.<p>I want to believe this. I want to be hyped. It sounds great. But there&#x27;s no reproduction scenario. Some claims are also false (php doesn&#x27;t kill the process to start the processing cycle). Others seem too good to be true - like 40x speedup.<p>It just smells like &quot;hey, we are cool kids too, look at us, we&#x27;re advertising using the hype that other kids use!&quot;.<p>If I&#x27;m able to reproduce 40x speedup, I&#x27;ll so gladly eat my words and flame myself.
ealexhudsonover 6 years ago
Without wanting to sound critical of this, they seem to have reinvented long-lived PHP servers. Gearman has allowed you to do this with PHP for almost ten years now, and it was even the case that you could plug it directly into mongrel2 with 0mq.<p>Fundamentally, it&#x27;s an idea that works incredibly well - it&#x27;s amazing that more people don&#x27;t make use of it....
评论 #18651474 未加载
z3t4over 6 years ago
Classic ASP is a similar framework to PHP. In Classic ASP there are a Session and a Application object. The Session object can store variables that will be available during the user session (using session cookie). And the Application object can store variables that will be available to <i>all</i> other scripts. So when the server starts, you put everything in the Application object, so when you get a new request, you load the data from the Application object instead of re-creating everything, doing database lookups etc on <i>every</i> request. This makes Classic ASP very performant with sub-millisecond requests. I used Classic ASP until recently and have now switched to Node.JS which uses an event loop. Per-request as in ASP and PHP is <i>much</i> easier then a event loop. In Node.JS for example, it&#x27;s very common to pull in a framework like Express to do the routing, while PHP and ASP already do that job for you. One problem with ASP and PHP however - they&#x27;re not optimal for real time stuff like chats or progress-bars.
perpetualcrayonover 6 years ago
I had a similar idea a while back. The implementation I came up with (but never implemented) was to create a PHP extension that would link to a statically compiled GO module. Basically it would instantiate a network server on the GO side, and marshal the HTTP request&#x2F;response data structures back and forth between PHP and Go. I imagined I would probably utilize a pthreads extension or one of the event loop extensions to handle each incoming request:<p><a href="http:&#x2F;&#x2F;php.net&#x2F;pthreads" rel="nofollow">http:&#x2F;&#x2F;php.net&#x2F;pthreads</a><p><a href="http:&#x2F;&#x2F;php.net&#x2F;manual&#x2F;en&#x2F;book.event.php" rel="nofollow">http:&#x2F;&#x2F;php.net&#x2F;manual&#x2F;en&#x2F;book.event.php</a>
rajangdavisover 6 years ago
Can anyone dumb this down for me?<p>I don&#x27;t really understand this use case - is this for PHP developers to eke out some more performance for their web apps?<p>The goridge library (<a href="https:&#x2F;&#x2F;github.com&#x2F;spiral&#x2F;goridge" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;spiral&#x2F;goridge</a>) makes a little more sense to me; it&#x27;s a bridge between golang and PHP via RPC.<p>I went through the code (<a href="https:&#x2F;&#x2F;github.com&#x2F;spiral&#x2F;roadrunner" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;spiral&#x2F;roadrunner</a>) but it doesn&#x27;t seem like something you can swap into an existing PHP project. Can anyone explain what use case this might be for?
评论 #18651988 未加载
xenaover 6 years ago
Found another rilkef: <a href="https:&#x2F;&#x2F;christine.website&#x2F;blog&#x2F;experimental-rilkef-2018-11-30" rel="nofollow">https:&#x2F;&#x2F;christine.website&#x2F;blog&#x2F;experimental-rilkef-2018-11-3...</a>
rakooover 6 years ago
Did they just reinvent FastCGI?
LolNoGenericsover 6 years ago
Usual question for this. How you handle sessions? The php built in is very bad if you recycle the main process.
fasteoover 6 years ago
am i missing something ? php-fpm can keep the process running as long as you want (pm.max_requests=0)
评论 #18653763 未加载
Kaverenover 6 years ago
PHP is the worst programming language ever made in current widespread use. There was never an excuse to use it, there were always other options, even many years ago.<p>&gt; &quot;To them, we say “think again.” We believe that the only limit PHP has is the limit you set.&quot;<p>You shouldn&#x27;t be writing PHP in the first place, and should slowly work to (incrementally, slowly) shift your codebase into any other programming language in existence if it is already written in PHP.<p>The core language is terribly designed. PHP 7 did not fix this. Even JavaScript is miles better (PHP has a type system equally as bad, if not worse).<p>Of course, this sentiment is unpopular, because you&#x27;re never supposed to rewrite anything even incrementally, and Popular Means Quality, and saying otherwise is heresy.<p>I propose the more radical solution of killing PHP entirely (again, incrementally, slowly), and replace it entirely with the language of your choosing (maybe that&#x27;s Go).
评论 #18651262 未加载
评论 #18651595 未加载
评论 #18655428 未加载
评论 #18651832 未加载
评论 #18651206 未加载
评论 #18652318 未加载
评论 #18651511 未加载