Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Making HttpRequest calls from PHP

  • 20-02-2009 1:35pm
    #1
    Registered Users, Registered Users 2 Posts: 6,469 ✭✭✭


    I'm a complete noob when it comes to PHP.
    I'm trying to do something fairly straightforward that I've already done in .Net - make a HttpRequest call to an external site and parse the results.

    I've got WAMP up and running after manually installing Apache and PHP.

    My problem is with the PHP HttpRequest class.
    From what I can find, it's not contained in the base PHP distribution, but in a set of extensions grouped under PECL?

    Problem is, on the PHP website, under the windows binaries downloads, there's a note reading: "Note: The PECL package will not be released for this version. The 5.2.6 PECL package does however work with this release". But there's no link to the 5.2.6 PECL package. And on the main page, there's the message: "Due to unfortunate circumstances Windows binaries for PECL extensions will no longer be available on http://pecl4win.php.net.".

    I did manage to find a PECL zip file somewhere but I'm not sure how up to date it is. I extracted the http_request.dll into my PHP folder, and added an Extension line referencing it in the php.ini file. Restarted the Apache server, but still seem to be getting an error on the HttpRequest call when loading the page.

    Do I need to do anything else to reference the http_request extension - any kind of 'include' in the PHP file?
    Also, the manual notes:
    In order to be able to load this extension on Windows, you additionally need to load the following PHP extensions: hash, iconv and SPL.

    Are these part of the base PHP distro or are they PECL extensions? Can't find them in the PECL zip file or in the PHP installation process under 'extensions'.

    I feel I'm missing something very obvious here, surely this shouldn't be this complicated? Is there maybe some more basic http_request support in standard PHP that I need to enable somehow? Any help appreciated!

    [edit]
    I'm using notepad++ with XDebug as my IDE - is there a better free one? Stepping through the code it just seems to end when I hit the HttpRequest line, but I'm not getting any error messages at all.

    Also, given that ultimately I'm hoping to have this hosted somewhere and run regularly with a cron job - would most hosts have common PECL extensions installed, or am I wasting my time here?


Comments

  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    What is it exactly that you're trying to achieve with the PHP code and I may be able to offer some suggestions? If you're just trying to reading data from the POST or GET streams then PHP has variables for each of these:

    POST:
    $myvar = $_POST["myvar"]; // where "myvar" is the id/name of the input
                                          // from the form
    

    GET:
    $myvar = $_GET["myvar"]; // where "myvar" is the id/name of the input
                                          // from the form
    

    -RD


  • Registered Users, Registered Users 2 Posts: 6,469 ✭✭✭MOH


    What is it exactly that you're trying to achieve with the PHP code and I may be able to offer some suggestions? If you're just trying to reading data from the POST or GET streams then PHP has variables for each of these:

    POST:
    $myvar = $_POST["myvar"]; // where "myvar" is the id/name of the input
                                          // from the form
    

    GET:
    $myvar = $_GET["myvar"]; // where "myvar" is the id/name of the input
                                          // from the form
    

    -RD

    Thanks, but what I'm trying to do is pull data from another site and write it to a DB.

    Basically something like this.


  • Registered Users, Registered Users 2 Posts: 6,469 ✭✭✭MOH


    Right, I knew I was being a complete gombeen. Just googled "php web crawler" and got my answer straightaway, whereas googling "php http request" was leading me all over the place.

    I believe what I was looking for was simply: file_get_contents()

    Hadn't copped you can just pass a URL and it retrieves the HTML, which is all I want.

    Nothing to see here, please move along :o


  • Closed Accounts Posts: 12,382 ✭✭✭✭AARRRGH


    Yeah, there are loads of ways of doing what you want to do.

    Another way is to use fsockopen to connect to the site, then use fputs to send header information (if you want to imitate a human using a browser), and then use fgets to read the HTML.


  • Registered Users, Registered Users 2 Posts: 605 ✭✭✭PaddyTheNth


    Another option is the cURL library...useful if the website requires authentication.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,045 ✭✭✭Bluefrog


    Some shared hosting providers won't support file-get_contents so better to use Curl IMHO.


  • Registered Users, Registered Users 2 Posts: 6,469 ✭✭✭MOH


    Bluefrog wrote: »
    Some shared hosting providers won't support file-get_contents so better to use Curl IMHO.

    Just when I had it working :(

    Might look into that then just in case, ta. If nothing else will be a learning experience.


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    cURL is good. Used it in the web texter scripts. Can handle cookies and everything too for you. Bare in mind some hosts mightn't have this module loaded either so do a echo phpinfo(); to see if its there.


  • Registered Users, Registered Users 2 Posts: 605 ✭✭✭PaddyTheNth


    If you're testing on WAMP you'll need to enable the CURL library...either right or left-click on the wampserver icon and go to php libraries or something like that...there's a popup list showing all the available modules and which are enabled. Just click on the entry for CURL to enable it.

    edit: left-click -> php -> php extensions is where you need to go.


  • Registered Users, Registered Users 2 Posts: 1,045 ✭✭✭Bluefrog


    MOH wrote: »
    Just when I had it working :(

    Might look into that then just in case, ta. If nothing else will be a learning experience.

    It's actually pretty easy - like someone else said, can even handle cookies for you. Much easier than doing the same kind of thing in .Net I think. Sometimes though, it's useful to have the threading in .Net - guess it depends on what you're doing.


  • Advertisement
Advertisement