Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a curl example in PHP example section #384

Closed
cuu508 opened this issue Jun 17, 2020 · 6 comments
Closed

Add a curl example in PHP example section #384

cuu508 opened this issue Jun 17, 2020 · 6 comments

Comments

@cuu508
Copy link
Member

cuu508 commented Jun 17, 2020

Suggested here: https://twitter.com/smknstd/status/1272818956076810247

image

Aside from the code sample, it will need some accompanying information–

  • is curl support typically built in with PHP, or does it need to be installed / enabled separately?
  • in the "20 retries, 5 second timeouts" example, what is the maximum amount of time it can use up?
  • is there a risk of curl code throwing exceptions? Should the snippet perhaps be wrapped in try..catch?

I'm very out of touch of today's PHP, so would appreciate any help.

@SuperSandro2000
Copy link
Contributor

is curl support typically built in with PHP, or does it need to be installed / enabled separately?

curl is a very common used php module but not installed when you install php on Debian.

in the "20 retries, 5 second timeouts" example, what is the maximum amount of time it can use up?

my uneducated guess would around about a minute.

is there a risk of curl code throwing exceptions? Should the snippet perhaps be wrapped in try..catch?

Nope but it could fail to connect in the same ways curl could which is not checked by this code.

https://stackoverflow.com/a/11297495/4446318

@smknstd
Copy link
Contributor

smknstd commented Jun 17, 2020

There is a php-curl module (https://www.php.net/manual/en/book.curl.php) but my example use a complete different library: https://github.com/php-curl-class/php-curl-class that looked convenient to me (install through composer + retry option).

is there a risk of curl code throwing exceptions?

no the library chose a different pattern php-curl-class/php-curl-class#403

What I was trying to say by "updating the doc", was not something specific to php but maybe a section on those options (timeout + retry) in general. Then each langage specific page could give insight on how to do it. It could be great to mention multiple solutions, for php I'd keep mentionning "file_get_contents" but adding "curl" + options

@smknstd
Copy link
Contributor

smknstd commented Jun 17, 2020

If you need snippet :

use Curl\Curl;

$curl = new Curl();
$curl->setRetry(20);
$curl->setTimeout(5);
$curl->get('https://hc-ping.com/your-uuid-here');     

@cuu508
Copy link
Member Author

cuu508 commented Jul 2, 2020

What I was trying to say by "updating the doc", was not something specific to php but maybe a section on those options (timeout + retry) in general. Then each langage specific page could give insight on how to do it.

That's a good idea! I've started work on the general page. Current version live here: https://healthchecks.io/docs/reliability_tips/

I'm confident I can also update Python examples, but for other languages help is very welcome.

@smknstd
Copy link
Contributor

smknstd commented Jul 7, 2020

the new page is great. Tried to update the php example here #395, hope it will help ...

@cuu508
Copy link
Member Author

cuu508 commented Jul 7, 2020

@smknstd thanks for the PR, looks good!

I noticed just now that PHP samples have no syntax highlighting. Related issue: Python-Markdown/markdown#334 I will keep an eye on python-markdown releases.

@cuu508 cuu508 closed this as completed Jul 7, 2020
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

No branches or pull requests

3 participants