-2

Let's say I have some project on php. One of its functions should be to check whether the latest version of php is used on the server. For example, for security reasons. There are no problems to use phpversion() and version_compare().

But how can I programmatically get the latest stable version of php? Maybe there is some kind of API or something like that?

General conditions:

  1. you need to get the latest release number of php using php itself;
  2. HTML parsing is not suitable;
  3. CLI or not — doesn't matter;
  4. it would be cool (but not necessary) to check the latest release within one major branch.

I am curious whether you had such a task and how you solved it.

This question is only about the software implementation of checking for updates, but not the update process itself.

closed as off-topic by gnat, Deduplicator, Jörg W Mittag, BobDalgleish, jwenting Jun 18 at 8:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking for assistance in explaining, writing or debugging code, or using coding tools, are off-topic here. These can be asked on Stack Overflow if they include the desired behavior, a specific problem or error, and a Minimal, Reproducible Example of the problem." – gnat, Deduplicator, Jörg W Mittag, BobDalgleish, jwenting
If this question can be reworded to fit the rules in the help center, please edit the question.

  • What should happen when there is a new PHP version that has not (yet) bee applied to the server? What if that new PHP version exists only for some operating systems/distros and not (yet) for the OS/distro being used by the server in question? – Bart van Ingen Schenau Jun 16 at 9:17
  • @BartvanIngenSchenau Ofcourse these nuances are important, but an opportunity to check for new versions of php by php-script is more interesting itself. The topic is about official releases and not about custom or "not popular" builds. So let's leave this questions to hypothetical server owner. He can get latest official php build for his server in different ways – Anthony Axenov Jun 16 at 10:13
  • I wan't thinking of custom/"not popular" builds, but of the fact that even the major Linux distributions will not have the new PHP version available at the same time it is published by the PHP maintainers. And some distribution might not even take it over if the new PHP version appears to have adverse effects or if the distribution only gets security updates. – Bart van Ingen Schenau Jun 16 at 12:40
  • And this completely ignores that company policy may dictate that a live server may not be updated until the new version has been validated in a test environment to ensure it won't break critical processes. – Bart van Ingen Schenau Jun 16 at 12:42
  • @BartvanIngenSchenau Try to abstract from all this. The question is only about the software implementation of checking for updates, and not the update itself. Server update is the task for server administrator. He can build php from source. Moreover, companies must have people responsible for such tasks. But it's not about that. – Anthony Axenov Jun 16 at 13:13
1

PHP source is hosted on GitHub, and GitHub has an API. Therefore, you can:

  1. Access the API in order to get the list of last revisions,
  2. Filter the ones you don't want (for instance the ones containing “alpha” or “RC” in the names).
  3. Parse the remaining revisions and sort the list (if you don't sort it, you'll get the revisions in the order when they were published; for example, at the moment of writing, php-7.2.19 appears more recent than php-7.3.6).
  4. Get the last one in the list.
  5. Compare.

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