Skip to content

Deploy SerpApi PHP library - #1

Merged
galetahub merged 102 commits into
masterfrom
Init
Aug 14, 2026
Merged

Deploy SerpApi PHP library#1
galetahub merged 102 commits into
masterfrom
Init

Conversation

@Alaa-abdulridha

Copy link
Copy Markdown
Collaborator

WIP

@Alaa-abdulridha Alaa-abdulridha added the WIP Work in progress label Nov 23, 2022
@Alaa-abdulridha Alaa-abdulridha self-assigned this Nov 23, 2022
@Freaky

Freaky commented Apr 9, 2024

Copy link
Copy Markdown

@Alaa-abdulridha I had a thought recently about how we go to the effort to create links back to the API, for example for pagination:

 "next": "https://serpapi.com/search.json?device=desktop&engine=google&gl=us&google_domain=google.com&hl=en&location=Austin%2C+Texas%2C+United+States&q=Coffee&start=10",

What do you think about our clients having direct support for these? A function that tacks on the API key, validates the endpoint and handles the request for you.

@Alaa-abdulridha Alaa-abdulridha removed the WIP Work in progress label Apr 9, 2024
@Alaa-abdulridha
Alaa-abdulridha requested review from Freaky and jvmvik April 9, 2024 22:13
@Alaa-abdulridha

Alaa-abdulridha commented Apr 9, 2024

Copy link
Copy Markdown
Collaborator Author

@Alaa-abdulridha I had a thought recently about how we go to the effort to create links back to the API, for example for pagination:

 "next": "https://serpapi.com/search.json?device=desktop&engine=google&gl=us&google_domain=google.com&hl=en&location=Austin%2C+Texas%2C+United+States&q=Coffee&start=10",

What do you think about our clients having direct support for these? A function that tacks on the API key, validates the endpoint and handles the request for you.

Thank you @Freaky , Good idea need more discussing, let's open an issue for it to address it later after deploying the library 👍

@jvmvik Sorry this took long 😞

@Freaky Freaky left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Alaa-abdulridha, just one or two comments! My PHP's pretty rusty, I need to catch up on modern best-practices.

Might be nice to have some phpdoc API docs?

Comment thread README.md.erb Outdated
Comment thread MIT-LICENSE.txt
@@ -0,0 +1,19 @@
The MIT License (MIT)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MIT license is supposed to have a copyright notice here, or it's a bit difficult to comply with the bit that starts "The above copyright notice".

Suggested change
Copyright 2024 SerpApi, LLC

Comment thread README.md.erb Outdated
Comment on lines +58 to +59
"engine" => "naver",
"query" => "paris",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't match the following text.

Suggested change
"engine" => "naver",
"query" => "paris",
"engine" => "google",
"q" => "coffee",

Comment thread README.md.erb Outdated
Comment thread README.md.erb Outdated
Comment thread README.md.erb Outdated
Comment thread README.md.erb Outdated
Comment thread src/serpapi.php Outdated
Comment thread src/serpapi.php Outdated
@@ -0,0 +1,167 @@
<?php

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was introduced after my PHP time, but I wonder if users generally expect libraries to be in their own namespaces these days?

Comment thread src/serpapi.php Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 34 out of 35 changed files in this pull request and generated 4 comments.

Comment thread src/Client.php Outdated
Comment thread src/Client.php Outdated
Comment thread Makefile Outdated
Comment on lines +1 to +2
# Default target
all: install readme test
Comment thread tests/ClientTest.php Outdated
Comment on lines +26 to +31
public function test_throws_when_api_key_invalid() {
$this->expectException(SerpApiException::class);
$this->expectExceptionMessageMatches('/Invalid API key/i');
$client = new Client('not_valid_key');
$client->search(['q' => 'Coffee']);
}

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 34 out of 35 changed files in this pull request and generated 2 comments.

Comment thread src/Client.php
Comment on lines +224 to +230
} finally {
if (PHP_VERSION_ID < 80500) {
curl_close($ch);
}

$ch = null;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curl_close() is deprecated as of PHP 8.5, so we intentionally avoid calling it on 8.5+.
The handle lifecycle is still bounded by try/finally, and we explicitly release the reference $ch = null to support long-running processes.
For legacy runtimes, we keep curl_close() behind PHP_VERSION_ID < 80500.”

Comment on lines +44 to +47
- name: Run test suite
run: composer run-script test
env:
API_KEY: ${{ secrets.API_KEY }}
@aciddjus

Copy link
Copy Markdown

@galetahub Is this ready for review?

@galetahub

Copy link
Copy Markdown
Contributor

@aciddjus, yes, it's ready for review.
Looks like copilot keeps generating the same comments each review cycle, so I've stopped fighting with it.
I've already asked @Alaa-abdulridha to review this PR.

@strzibny

Copy link
Copy Markdown

Since we are building the client using classes, should we use camelCase? e.g. getApiKey()?

@galetahub

Copy link
Copy Markdown
Contributor

Good call, @strzibny! That's actually codified in PSR-1 (PHP Standard Recommendation). I'll fix the method names. I think we should also set up a linter for this.

@strzibny

Copy link
Copy Markdown

We can also consider matching https://www.php-fig.org/psr/psr-12/

@galetahub

Copy link
Copy Markdown
Contributor

@strzibny, thanks for looking into it!

The latest updates:

  1. Renamed methods and properties to camelCase for PSR-1 consistency
  2. Set up a linter with extended coding style https://www.php-fig.org/psr/psr-12/
  3. Added badges to the readme
  4. Temporarily skip Google events test due to its unavailability.

@strzibny

Copy link
Copy Markdown

Things generally work for me, I haven't faced a major issue in writing and testing different scripts.

Some other things we could consider.

1, Adding PHPStan (we would need to stay on 1.x because of our PHP 7.2support)

2, Extend scripts and remove vendor/bin as it's automatically added by Composer

"scripts": {
        "test": "vendor/bin/phpunit -c phpunit.xml",
        "lint": "vendor/bin/phpcs",
        "analyse": "phpstan analyse src tests",
        "check": [
                "@lint",
                "@analyse",
                "@test"
            ]
    }

3, Extend support fields

"support": {
    "issues": "https://github.com/serpapi/serpapi-php/issues",
    "source": "https://github.com/serpapi/serpapi-php",
    "docs": "https://serpapi.com/integrations/php"
}

4,

Personally I love being able to test libraries offline and I also dislike project README badges (they are native GitHub features for most, they add the issue of not being always loaded, they scream RED and therefore are offputting to users), but I understand this is the case for our other libraries to and it's just a matter of taste.

@aciddjus

Copy link
Copy Markdown

@strzibny, can you approve the PR or request changes so that @galetahub knows what the next steps should be?

I would rather release this sooner than later if stable, because we have known issues with the current library that are preventing users from using it efficiently.

@galetahub

Copy link
Copy Markdown
Contributor

Thanks for your comment, @strzibny!

  1. Adding PHPStan (we would need to stay on 1.x because of our PHP 7.2support)

Currently, this library has a small src/ surface (mainly two classes), and we already cover style with PHPCS and behavior with PHPUnit. Happy to revisit if the codebase grows or we want stricter static analysis later.

  1. Extend scripts and remove vendor/bin as it's automatically added by Composer

Agree with you. I removed vendor/bin as it's automatically added.

  1. Extend support fields

Done.

  1. Personally I love being able to test libraries offline and I also dislike project README badges (they are native GitHub features for most, they add the issue of not being always loaded, they scream RED and therefore are offputting to users), but I understand this is the case for our other libraries to and it's just a matter of taste.

According to the badges we use in other integration libraries, I think it makes sense to keep them here as well. For me, badges add a bit more trust to the library 😃.

@galetahub

Copy link
Copy Markdown
Contributor

After discussing it with @strzibny, we concluded that we should remove the CI badge and package downloads counter. The CI badge duplicates a native GitHub feature, sometimes badge won't load or shows a failed build.

@strzibny strzibny left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

@galetahub
galetahub merged commit 7bdd8b7 into master Aug 14, 2026
2 of 10 checks passed
@aciddjus

Copy link
Copy Markdown

Thank you, @galetahub 👍

Can you please open a follow-up PR to replace the old version with the new on the website?

Similar to: https://github.com/serpapi/SerpApi/pull/9618


BTW, there is a package badge seam to be broken.

CleanShot 2026-08-14 at 13 43 35@2x

@galetahub

Copy link
Copy Markdown
Contributor

@aciddjus, thanks for pointing it out.
I’ll create a follow-up PR

The package hasn’t been published yet, so the package badge is broken. I'm going to do it via GitHub actions.
BTW, the package version will be 1.0.0.

@aciddjus

Copy link
Copy Markdown

Got it. Thank you, sounds good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants