{"id":527,"date":"2008-01-18T22:07:16","date_gmt":"2008-01-18T22:07:16","guid":{"rendered":"http:\/\/neosmart.net\/blog\/2008\/dont-believe-the-lies-php-isnt-thread-safe-yet\/"},"modified":"2013-08-26T18:18:01","modified_gmt":"2013-08-26T23:18:01","slug":"dont-believe-the-lies-php-isnt-thread-safe-yet","status":"publish","type":"post","link":"https:\/\/neosmart.net\/blog\/dont-believe-the-lies-php-isnt-thread-safe-yet\/","title":{"rendered":"Don&#8217;t Believe The Lies: PHP Isn&#8217;t Thread-Safe Yet"},"content":{"rendered":"<p>If you took everything you heard for granted, you&#8217;d have been lead to believe that the official PHP distributions (from php.net) have been thread-safe since version 5.2.0.<\/p>\n<p>That&#8217;s not true. Don&#8217;t fall for it. Don&#8217;t attempt to use PHP in a multi-threaded environment (mpm_worker on Apache, ISAPI on IIS, etc.), because PHP thread-safety is a myth.. nothing more than a bunch of lies, if you will.<\/p>\n<p>If you look at the <a href=\"http:\/\/www.php.net\/downloads.php\" rel=\"follow\">PHP download page<\/a>, you&#8217;ll see that the pre-built binaries (in this case, Windows) are split into two: thread-safe and non-thread-safe:<\/p>\n<p><img class=\"colorbox-527\"  loading=\"lazy\" decoding=\"async\" style=\"border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px\" height=\"285\" alt=\"Thread-Safety\" src=\"\/blog\/wp-content\/uploads\/thread-safety.png\" width=\"591\" border=\"0\"\/><\/p>\n<p>The problem is, no matter which you choose, PHP isn&#8217;t thread safe. You&#8217;ll still get the <a href=\"http:\/\/www.vbulletin.com\/forum\/forum\/general\/php-html-questions\/209542-http-500-php-access-violation-on-iis-w-isapi\" rel=\"follow\">same<\/a>, <a href=\"http:\/\/www.phpwsforums.com\/showthread.php?t=526\" rel=\"follow\">old<\/a>, <a href=\"http:\/\/www.google.com\/search?hl=en&amp;client=opera&amp;rls=en&amp;hs=TpJ&amp;q=%22PHP+has+encountered+an+Access+Violation+at+%2A%22&amp;btnG=Search\" rel=\"follow\">dreaded<\/a> &#8220;PHP has encountered an access violation at <em>memory_address<\/em>&#8221; error.<\/p>\n<p>It&#8217;s not a question of server configuration so much as it is one of PHP writing bad code and pretending that&#8217;s not the case. PHP isn&#8217;t multi-threading ready and most everyone knows it&#8230; but it seems they still feel the need to pass it off as if it were, never mind the complaints and bug reports that come.<\/p>\n<p><!--more--><\/p>\n<p>There isn&#8217;t a known solution to this problem. The source code for the official PHP distribution is simply not re-entrant and isn&#8217;t capable of being used in multi-threaded environments. It&#8217;s filled with race conditions and lacks the proper monitors\/locks on shared memory spaces (which needn&#8217;t be shared in the first place). Unfortunately, there&#8217;s not much more to be said; making this post more of a rant than a guiding light for those of you experiencing this issue.<\/p>\n<p>At NeoSmart Technologies we still recommend the only other production-ready, decently-performing *sapi alternative; which is the deployment of PHP <a href=\"https:\/\/neosmart.net\/blog\/opensource-on-windows-and-iis\/\" rel=\"follow\">by means of the FastCGI protocol<\/a>. Whether on Linux or Windows, FastCGI scripting engines are considerably faster than their age-old CGI implementations (though the outcome is more-clearly felt on Windows where the CGI model is hideously slow). But we&#8217;ve already discussed this before, <a href=\"http:\/\/www.google.com\/search?hl=en&amp;client=opera&amp;rls=en&amp;hs=asJ&amp;q=+site%3Aneosmart.net+PHP+FastCGI&amp;btnG=Search\" rel=\"follow\">countless times<\/a>.<\/p>\n<p>The moral of the story is that PHP isn&#8217;t multi-threaded &#8211; yet if you go by what they say, you&#8217;d come to think it was&#8230; until you try it out for yourself and realize that not a darn thing has changed in the 5.2.x releases when it comes to thread-safety and the deployment of PHP in multi-threaded environments.<\/p>\n<p>If you still insist on using ISAPI implementations, you should probably use the latest versions of the PHP4 distribution instead. The older PHP line is less-apt to cause an access-violation error on your machine, and will more than outclass the PHP5 &#8220;thread-safe&#8221; distributions when it comes to reliability.<\/p>\n<p>PHP needs to clean up their act and either produce real (and verifiably so) thread-safe, re-entrant code or stop the false propaganda that would lead you to believe it&#8217;s thread-safe in its current incarnation &#8211; especially when most other dynamic scripting languages (such as Perl) have proper, thread-safe engines available.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you took everything you heard for granted, you&#8217;d have been lead to believe that the official PHP distributions (from php.net) have been thread-safe since version 5.2.0. That&#8217;s not true. Don&#8217;t fall for it. Don&#8217;t attempt to use PHP in &hellip; <a href=\"https:\/\/neosmart.net\/blog\/dont-believe-the-lies-php-isnt-thread-safe-yet\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[360,297,299,588,124],"class_list":["post-527","post","type-post","status-publish","format-standard","hentry","category-software","tag-coding","tag-fastcgi","tag-isapi","tag-multi-threading","tag-php"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4xDa-8v","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/527","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/comments?post=527"}],"version-history":[{"count":2,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/527\/revisions"}],"predecessor-version":[{"id":2491,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/527\/revisions\/2491"}],"wp:attachment":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/media?parent=527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/categories?post=527"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/tags?post=527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}