3
$\begingroup$

I read some information1 about attempts to build neural networks in the PHP programming language. Personally I think PHP is not the right language to do so at all probably because it's a high-level language, I assume low level language are way more suitable for AI in terms of performance and scalability.

Is there a good/logical reason why you should or shouldn't use PHP as a language to write AI in?

1 http://www.developer.com/lang/php/creating-neural-networks-in-php.html and https://stackoverflow.com/questions/2303357/are-there-any-artificial-intelligence-projects-in-php-out-there

$\endgroup$
  • 3
    $\begingroup$ After reconsidering, this question is too much about the implementation side of things rather than the academic humanities - this is a technological question, and that's great, but we were going to be not about technology and more about the other aspects of AI and ... this is exactly an implementation kind of question. $\endgroup$ – Pimgd Aug 4 '16 at 12:50
  • $\begingroup$ While I have mixed feelings on the whole "no implementation questions" issue, here I have to agree - this is definitely too much about implementation and too little about AI itself. $\endgroup$ – Disenchanted Lurker Aug 4 '16 at 13:43
  • $\begingroup$ Though regarding the low-level vs. high-level language question, I would say that as far as neural networks are concerned, your assumption is false. Most of the people I know who work with neural networks use Python, which is very much a high-level language. It also offers several frameworks for the purpose (e.g. Theano, Caffe, TensorFlow). $\endgroup$ – Disenchanted Lurker Aug 4 '16 at 13:51
6
$\begingroup$

Question on-topicness questionable, but...


The most logical reason why PHP is unsuited for neural networks is that PHP is, well, intended to be used for server side webpages. It can connect to various external resources, such as databases, via native language features. It is very much a glue language, and not a processing language. PHP is also mostly stateless, only allowing you to store state in either clients, file storage or databases.

As such, it's not suitable for this sort of thing - not because PHP is a high level language, but rather because it's so request based and focused towards creating pages to serve to clients.

That won't stop people from trying, though - there are various esoteric programming languages out there in which regular programming would be an insane task or not possible at all - but from a ease of development perspective, making a neural network in PHP makes no sense.

| improve this answer | |
$\endgroup$
  • $\begingroup$ While PHP originated via a web page serving background it is not correct to say that it cannot be used for processing or that it is necessary for any language to be stateful between executions - that is what storage is for. $\endgroup$ – A Smith Jan 4 '17 at 1:16
  • $\begingroup$ It is possible if PHP is Turing-Complete (or a computational class which could support neural networks), but would probably have speed issues because PHP isn't exactly made for algorithms, but for server-side websites. $\endgroup$ – MilkyWay90 Feb 20 '19 at 4:37
3
$\begingroup$

Actually, yes. Remember, that due to the history of PHP development, some very good things has formed what we have now:

  • From a simple/laggy/limited interpreter in PHP 3, we have now three mainstream lines coming one-by-one like v5/v6/v7 with full bytecode supported.

  • In PHP v7 you don't even need a bytecode cache due to HHVM, old Zend VM is a hell-good-debugged and using a cacher like XCache you can achieve a true native execution speed and payload

  • The PHP language interface allows any external C/C++ library just to be added as a module via very simple wrapper that can be written by the person that just red Kerrigan&Richie and Straustrup base books on C and C++. This is amazing feature, exclusive to PHP as far as I know

  • In PHP v7 you're welcome to use native multi-threading and even CUDA-based things, if you wish to do it. I did it, so I can confirm that it works

| improve this answer | |
$\endgroup$
  • $\begingroup$ Those are just reasons that it isn't necessarily as slow as we might think. Speed is nice, but it doesn't outweigh the issues listed by @Pimgd. Contrast with Python which is another modern scripting language that is much better for AI: Python supports external libraries for speed; has great collection support; can be run interactively; and isn't crippled (from an AI perspective) by the request-based nature. Perhaps these are the reasons there are more well-known AI libraries for Python, such as NLTK? $\endgroup$ – winwaed Aug 4 '16 at 13:49
  • 3
    $\begingroup$ @winwaed actually, PHPv7 is not request-based at all, can be run interactively, it has 100% native threading support, external library interfacing is a bit more complicated than in PHP: I used to interface a C++ library to Python2 and PHP5 at the same time, and the process differs greatly. $\endgroup$ – Alexey Vesnin Aug 4 '16 at 14:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.