Why am I getting an error when requiring a file in my plugin?

As the names suggest, plugin_dir_path() will get the filesystem path, while plugin_dir_url gets the URL.

A file path looks something like this /var/www/html/wp-content/plugins/my-plugin/ and can be used by PHP to find a file on the server.

A URL will look like https://www.example.com/wp-contents/plugins/my-plugin/ and is intended to be accessed over the web. If you attempt to require a file in PHP using a URL the server will need to request that file over the web, which is far far slower, and a security risk. This is why the ability to even do this is disabled by default in many setups. The error you’re seeing is telling you that this is disabled.

File paths should be used for accessing files on the server, while URLs should be used to find assets from the browser.

tech