2017-10-13 08:48



I'm trying to use https://github.com/phpWhois/phpWhois in my PHP scripts, but can't get it to work. I'm an absolute beginner when it comes to using Composer.

This is what I tried:

  • Cloned the git repo locally
  • Installed Composer for Windows
  • In Powershell, navigated to the local repository
  • Typed composer require. Composer first asked me: Search for a package:, where I simply pressed ENTER. Then, Composer installed various packages in the vendor directory (phpunit, symfony, sebastian, etc.), and it created an autoload.php file.

But if I include that autoload.php in my example script (the basic example on the phpWhois Github main page), it generates the following error:

Fatal error: Class 'phpWhois\Whois' not found in /home/myServer/www/myApp/api/whoistest.php on line 12

Well, the Installation manual on the Github page says I should run

php composer.phar require "phpwhois/phpwhois":"~4.0"

So I tried the following in the Powershell console:

composer require "phpwhois/phpwhois":"~4.0"


Could not parse version constraint :~4.0: Invalid version string ":~4.0"

Then this:

composer require "phpwhois/phpwhois"

Problem 1

  • Conclusion: remove phpwhois/phpwhois dev-master
  • Can only install one of: phpwhois/phpwhois[dev-master, 4.2.3].
  • Can only install one of: phpwhois/phpwhois[dev-master, 4.2.4].
  • Can only install one of: phpwhois/phpwhois[v4.2.5, dev-master].
  • Installation request for phpwhois/phpwhois dev-master -> satisfiable by phpwhois/phpwhois[dev-master].
  • Installation request for phpwhois/phpwhois ^4.2 -> satisfiable by phpwhois/phpwhois[4.2.3, 4.2.4, v4.2.5].

Then this:

composer require "phpwhois/phpwhois:~4.0"

which gave the same error as above.

I tried various other syntaxes to specify the version here, but none of them worked.

Any ideas?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • douwen1549 douwen1549 4年前

    Ok, let's start from the beginning.

    1. Download the latest composer.phar from getcomposer.org (scroll down to manual install).
    2. Put it in your project root directory.
    3. Remove all your current require statements from your composer.json.
    4. Open a terminal and navigate to your project root.
    5. Execute php composer.phar require phpwhois/phpwhois.
    6. Execute php composer.phar install.
    7. Include the autoloader in your code: require vendor/autoload.php.
    点赞 评论 复制链接分享