Skip to main content

PHPBot – Can a PHP Bot Help You Look up Documentation Faster? best php Training Trivandrum

PHPBot – Can a PHP Bot Help You Look up Documentation Faster?


I came across PHPBot the other day (not to be confused with Botman or Fondbot) – a “chatbot” which helps you look up PHP manual entries and generates example code for them.
If you follow me on Twitter, you know I don’t believe in chatbots being chatbots – as someone who’s built some for both commercial purposes and personal ones, and as someone who was around in the age of IRC auto-responding scripts, I see chatbots as a little more than a marketing fad designed to impress today’s Snapchat generation. However, every now and then one will appear that’s actually useful. Could this be the one? Let’s take a look.
Bot welcoming image

Concept

The idea is that you use the text input on the page to enter a PHP related term (like “ksort”) and the application will reply with an explanation and some example code, like so:
PHPBot reply to ksort input
Different queries will produce different responses. So, if you ask it for echo:
PHPBot's reply to echo

Usefulness

While this sounds interesting in theory, in practice it’s a bit off.

Knowledgebase and Bugs

The knowledge the bot can provide is limited at best. For example, asking it for preg_split copies the first example from the manual entry, but fails to recognize the newline and messes things up:
Preg split PHPBot response
Magic methods don’t seem to be supported:
PHPBot's response to __toString
And some queries will just fail, purely because there’s no example in the manual that the bot can find:
PHPBot's response to exec

Autocompletion / Suggestion

For the queries it doesn’t recognize, or for those a user had just started typing, it would be nice to have some kind of autocomplete or autocorrect dropdown – or at the very least, when asking for the wrong thing, the bot should be able to infer what we meant and suggest that. For example, preg_split which is identical to explode only it uses regex to split a string is quite stupidly named, and the bot recognizing this when we ask for preg_explode would be a great feature addition.
preg_explode produces nothing useful in PHPBot

Copy / Paste Friendliness

The snippets the bot returns are just code-highlighted blocks of text, but they’re not very copy-paste friendly. The lines don’t wrap either, so you’re never sure what you’re copying, and the bot sometimes misformats an example and messes up new lines, making it even less paste-friendly:
Broken newlines in returned example
A standardized shape of returned data would benefit the project considerably. A PSR-2 formatted plain-text output comes to mind as something cross-platform friendly which could then be consumed by any custom-made client (see API below).

API

The app as-is provides no API access, so it can only be used in a separate tab / browser. In an era where we all have over 20 tabs open at any one given time while working, yet another one isn’t exactly too useful – it’d work much better as a browser extension, really, but even better if it had an API.
Being able to implement it with any third party tool, client, or IDE would actually be quite exciting, and would significantly augment tools like class templates and code snippets in IDEs like PhpStorm!

Source Code

Right now, PHPBot is closed source. I assume this is because it was quickly hacked up and is little more than a crawler which grabs the relevant example from a queried method, if it can find one. That’s understandable, but I would encourage the author to clean up the code and open source it as soon as possible so that we as a community can dig in and make it do things the author didn’t think of.

Conclusion

PHPBot, while less a bot and more an “interactive” search field for the PHP manual with examples, has a limited scope of use. Right now, its knowledgebase is minute, and the examples within are less than useful. It’s a cute experiment, but little more than that.
At this point in time, I’d sooner recommend a thing like DevDocs which contains the full manual and works offline, thus being extra fast. PHPBot does show potential as an interesting tool / experiment, but won’t realize that potential until it opens up its source code and allows people to contribute example code to generate, and APIs to implement its responses in traditional chatbots that can be integrated with CLI tools, IDEs, and maybe even IM application clients – then, having an interactive, responsive, user-upgradeable manual that can be fully integrated with one’s local tool will become a game-changer.

Comments

Popular posts from this blog

Memory leak in 7.x json_decode()? Best Php Training Trivandrum

Memory leak in 7.x json_decode()? There appears to be a memory leak in 7.x json_decode(). I've uploaded a huge JSON file to demonstrate the problem. Here is the sample code: <?php echo memory_get_usage(false) . ' : ' .memory_get_usage(true) . PHP_EOL; $json = json_decode(file_get_contents('http://zaremedia.com/big.json')); echo memory_get_usage(false) . ' : ' .memory_get_usage(true) . PHP_EOL; unset($json); echo memory_get_usage(false) . ' : ' .memory_get_usage(true) . PHP_EOL; Below is output from 7.x and then 5.6: // Running on 7.0 and 7.1 349608 : 2097152 27245512 : 29360128 375552 : 29360128 The process starts with 0.3mb used / 2.0mb allocated. After json_decode(), it's 27.2 / 29.4mb, after unset, it's 3.7mb / 29.4mb -- The second value (memory allocated by php via emalloc()) has not been freed, though PHP's gc has correctly freed up the object usage. // Running on 5.6 221136 : 262144 31577064 : 35913728 420104 : 86507

How do I deploy my Symfony API - - Deploy best php training trivandrum

How do I deploy my Symfony API -  - Deploy This is the forth post from a series of posts that will describe the whole deploy process from development to production.  The first article is available  here , the second  here  and the third  here . After covering the steps 1-3 and having prepared our infrastructure, we can see how to  deploy  our application to production. Almost the same approach can be used to deploy not only to production but also to test environments. Workflow Different "git push" operation should trigger different actions. Just as example a push to  master  should trigger a deploy to production, while other branches may trigger a deploy to a test environment, or not trigger deploys at all. I've used  Circe CI Workflows  to manage this set of decisions. Workflows are just another section from the same  .circleci/config.yml  file and here they are: workflows: version: 2 build_and_deploy-workflow: jobs: - build - d

A DateTimePeriod library for working with temporal intervals php training trivandrum

An implementation of the datetime period type for working with temporal intervals. The library includes the full set of relations on intervals defined by  Allen's Interval Algebra . For further information see the "Usage" and "How it works" paragraphs. Requirements PHP 7.1+ Installation $ composer require pwm/datetime-period Usage Creation: $start = new DateTimeImmutable ( ' 2010-10-10T10:10:10+00:00 ' ); $end = new DateTimeImmutable ( ' 2011-11-11T11:11:11+00:00 ' ); $period = new DateTimePeriod ( $start , $end ); // Start/end instants and their interval $start = $period -> getStart(); // DateTimeImmutable('2010-10-10T10:10:10+00:00') $end = $period -> getEnd(); // DateTimeImmutable('2011-11-11T11:11:11+00:00') $interval = $period -> getInterval(); // DateInterval('P1Y1M1DT1H1M1S') Restrictions: // Throws TimeZoneMismatch exception new DateTimePeriod ( new Da