I need help guys, are you familiar with the alchemy api? its a seo tool that runs on different platforms and what it does it extracts contents from web pages it uses the principle of content scraping. I downloaded the php SDK for alchemy api and i got an error i cannot load the page and if anyone here in this forum that is familiar with alchemy api or good with php i really need your help guys. the error says Fatal error: Class 'AlchemyAPI' not found in line 44

function CheckNoParams() {

$alchemyObj = new AlchemyAPI();//line 44
$alchemyObj->loadAPIKey("api_key.txt");


$htmlFile = file_get_contents("../example/data/example.html");
$htmlFile2 = file_get_contents("../example/data/example2.html");

Dani AI

Generated

A focused checklist for that follows up on ’s suggestions: the fatal class-not-found situation almost always means PHP never loaded the SDK class (or the SDK file declares a different class/namespace). The file_get_contents vs. cURL point is useful for fetching example HTML, but first confirm the SDK itself is being included and that the class name you instantiate actually exists in the SDK file.

Concrete steps to try (in order):

  1. Confirm the SDK file is present and included before you instantiate anything. Build an absolute path (use __DIR__) rather than a fragile relative path.
  2. Open the SDK file and check the exact class declaration and whether it uses a namespace. If there’s a namespace, instantiate using the fully qualified name or add a use clause, or require Composer’s vendor/autoload.php instead.
  3. Watch case-sensitivity: filenames and class names are case-sensitive on Linux hosts.
  4. Use quick runtime checks (file existence, readability, and class_exists) to produce a clear error before you try to create the object.
  5. Verify the API-key and example files exist at the paths your script expects and have correct permissions. If your environment blocks remote file_get_contents, either enable allow_url_fopen or fetch with cURL (as @Dani suggested).

Example diagnostic snippet (put this at the top of the script that will create the SDK object):

<?php
$sdkFile = __DIR__ . '/lib/AlchemyAPI.php';
if (!is_readable($sdkFile)) {
    error_log("Alchemy SDK not found or unreadable at: $sdkFile");
    exit;
}
require_once $sdkFile;

if (!class_exists('AlchemyAPI')) {
    error_log('AlchemyAPI class not available after include. Open the SDK file to confirm class name and namespace.');
    exit;
}

If those checks pass but the problem remains, paste the first ~50 lines of the SDK file (the namespace and class declaration) and the exact include/require line you used. That will make it trivial to point out the mismatch. Avoid turning on display_errors on a production server — use logs for diagnostics.

Recommended Answers

All 2 Replies

I've never heard of Alchemy at all but it's possible that your hosting company doesn't support file_get_contents(). Try using cURL instead.

Better yet, can you tell us what the error message is??

Oh, and incidentally, here's how you would use cURL instead of file_get_contents():

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, '');
$htmlFile = curl_exec($ch);
curl_close($ch);

Like I said, there's not much help that I can offer without knowing what the error message is. It's possible that you are specifying the wrong path for the api_key text file or the wrong path for the example data. It's possible that your server doesn't support file_get_contents(). It's possible that you're not including the AlchemyAPI class within the php file that is declaring the alchemy object. Lots of things could be the issue here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.