Git Product home page Git Product logo

Comments (9)

lyrixx avatar lyrixx commented on August 24, 2024 1

Indeed, I don't know why. But since there is a much better way to do, let's close this for now.

Thanks for the issue!

from castor.

arnolem avatar arnolem commented on August 24, 2024

I have implemented a workaround at PHP level but it is not ideal

file_get_contents('https://[...]', context: stream_context_create([
    "ssl" => [
        "verify_peer"      => false,
        "verify_peer_name" => false,
    ],
]));

from castor.

lyrixx avatar lyrixx commented on August 24, 2024

Is the URL Public so we can test? Or does it work with GitHub.com for example?

If you have SSL error you can also use the http client with some options to disable peer verification

from castor.

arnolem avatar arnolem commented on August 24, 2024

Yes

#[AsTask(description: 'https://github.com/jolicode/castor/issues/430')]
function issue430()
{
    file_get_contents('https://github.com/jolicode/castor/blob/main/composer.json');
}

it works with Castor but it doesn't work with binary

image

Maybe it's a cacert.pem problem but it's not present in Castor either and it works

image

from castor.

lyrixx avatar lyrixx commented on August 24, 2024

Hello, I tried the following setup

  1. download a static binary: https://castor.jolicode.com/getting-started/installation/#as-a-static-binary
  2. Create a new castor.php with the following content:
    <?php
    
    use Castor\Attribute\AsTask;
    
    use function Castor\io;
    use function Castor\request;
    
    #[AsTask(description: 'Make HTTP request')]
    function httpRequest(string $url = 'https://example.com'): void
    {
        $response = request('GET', $url);
    
        io()->writeln($response->getContent());
    }
  3. Execute it:
    $ ./castor-static  http | head
    <!doctype html>
    <html>
    <head>
        <title>Example Domain</title>
    
        <meta charset="utf-8" />
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <style type="text/css">
        body {
    $ ./castor-static  http --url  "https://github.com" | head
    
    
    
    
    
    
    <!DOCTYPE html>
    <html
      lang="en"
      
  4. ensure I got the static binary
    $ file ./castor-static
    ./castor-static: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped

Everything works as expected. what did I miss?

from castor.

lyrixx avatar lyrixx commented on August 24, 2024

For the record, I also repack + compile my app, end it still work

$ /tmp/foobar/castor-ssl/my-app.linux.x86_64 http
<!doctype html>
<html>
<head>
    <title>Example Domain</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
    body {
        background-color: #f0f0f2;
        margin: 0;
        padding: 0;
...

from castor.

lyrixx avatar lyrixx commented on August 24, 2024

And I even try in an alpine container:

$ docker run -it  -v $(pwd):/app --rm alpine  /app/my-app.linux.x86_64 http
<!doctype html>
<html>
<head>
    <title>Example Domain</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
    body {
        background-color: #f0f0f2;
        margin: 0;
        padding: 0;
        font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
        
    }

from castor.

arnolem avatar arnolem commented on August 24, 2024

Thanks a lot !

There is no problem with request()

// β˜‘οΈ OK
$response = request('GET', 'https://github.com/jolicode/castor/blob/main/composer.json');
$json = $response->getContent();

But there is a problem with file_get_contents()

// 🚫 WARNING
$json = file_get_contents('https://github.com/jolicode/castor/blob/main/composer.json');

I'm going to use request() for now but there is a problem with certificates if we directly use a native PHP function.

from castor.

arnolem avatar arnolem commented on August 24, 2024

This thread documents this issue πŸ‘

from castor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.