Posted: Thu Aug 16, 2007 5:13 am
In essence, the question would be: Does your ISP allow you (the useraccount that executes the php script) to make an outgoing connection to (server, port)?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
I already stated that I can not use the port on my server to connect to a remote server, thus I can not use cURL methods. My only option is to make a post request.In essence, the question would be: Does your ISP allow you (the useraccount that executes the php script) to make an outgoing connection to (server, port)?
I don't mean to argue with you but it's a bit confusing. Didn't you say "Generally - no, you don't need." in response to my post prior? And doesn't "Generally - no, you don't need." mean I don't need to open a port, but now you say I do? Or is it just a misunderstanding? You thought that the port of mine is already open and I don't need to open it so you said "Generally - no, you don't need.", rather then what I really meant which is that my port isn't open and I'm not authorized to open it.VladSun wrote:Are you sure about this? Because even with fskopen you need a local port to be opened ... That is the way Internet works
Code: Select all
// Request
$request = "POST /path HTTP/1.0\r\n"
. "Host: domain.tld\r\n"
. "Content-Type: application/x-www-form-urlencoded;\r\n"
. "Content-Length: " . strlen($dataToPost) . "\r\n"
. "\r\n"
. $dataToPost;
$fs = @fsockopen($host, $port, $errno, $errstr, 10);
fwrite($fs, $request);
// Response
$response = '';
while (!feof($fs)) {
$response .= fgets($fs, 1160);
}
fclose($fs);
It's pretty self-explanatory. Read the documentation on the functions, learn a little bit about sockets, and TRY IT. You'll never know if it'll work if you don't try it.JellyFish wrote:So can someone explain to me what this script does line-by-line
In my understanding (as network admin) this mean: Do I need to call my hosting support and inform them that you want to make some outgoing connections so they have to change the server firewall settings to allow you. In short:JellyFish wrote:Does this mean that I don't need a port open for my server?
The second part of my post you are quotting was an explanation for what I'd written above:JellyFish wrote: I don't mean to argue with you but it's a bit confusing. Didn't you say "Generally - no, you don't need." in response to my post prior? And doesn't "Generally - no, you don't need." mean I don't need to open a port, but now you say I do? Or is it just a misunderstanding? You thought that the port of mine is already open and I don't need to open it so you said "Generally - no, you don't need.", rather then what I really meant which is that my port isn't open and I'm not authorized to open it.![]()
Exactly!JellyFish wrote: And if all posts to a server need to open a port in order to interact ...
While you are browsing in you favorite browser type in the command prompt/console:JellyFish wrote: ... than who's port is being opened when ajax or an html form makes a request?
If you are sending HTTP request, by default the destination port is 80, and the source port (that's the port which gets opened in your understanding) is usually above 1024 and it must be a free port (i.e. not used by any other process at the local machine). So, you cannot say that it would always be 1129.JellyFish wrote: Is it the clients ports that are both connecting? And more importantly, which port umber is being used, to be specific? The usual port 80 is fine, it's just port number 1129 that I'm having trouble with.
JellyFish wrote:
Also is a socket just a connection between two ports?![]()
SOCKET
(1) In UNIX and some other operating systems, a software object that connects an application to a network protocol. In UNIX, for example, a program can send and receive TCP/IP messages by opening a socket and reading and writing data to and from the socket. This simplifies program development because the programmer need only worry about manipulating the socket and can rely on the operating system to actually transport messages across the network correctly. Note that a socket in this sense is completely soft - it's a software object, not a physical component.
Woaw!!! Wowy wow wow wowww! This clears sooooooo many things UP! Where in the world did you find that description?!?!VladSun wrote:SOCKETJellyFish wrote:Does this mean that I don't need a port open for my server?
(1) In UNIX and some other operating systems, a software object that connects an application to a network protocol. In UNIX, for example, a program can send and receive TCP/IP messages by opening a socket and reading and writing data to and from the socket. This simplifies program development because the programmer need only worry about manipulating the socket and can rely on the operating system to actually transport messages across the network correctly. Note that a socket in this sense is completely soft - it's a software object, not a physical component.
Code: Select all
<?php
function HttpRequest($address, $data)
{
$url = parse_url($address);
while (list($key, $value) = each($data))
{
$dataToPost .= "$key=$value&";
}
$dataToPost = rtrim($dataToPost, "&");
$request = "POST ".$url['path']." HTTP/1.0\r\n"
. "Host: ".$url['host']."\r\n"
. "Content-Type: application/x-www-form-urlencoded;\r\n"
. "Content-Length: ".strlen($dataToPost)."\r\n"
. "\r\n"
. $dataToPost;
$socket = @fsockopen($url['host']);
fwrite($socket, $request);
// Response
$response = '';
while (!feof($socket)) {
$response .= fgets($socket, 1160);
}
fclose($socket);
return $response;
}
?>Code: Select all
$transaction = HttpRequest("https://www.linkpointcentral.com/lpc/servlet/lppay", $myorder);What am I missing? An argument for fsockopen? All the other parameters other then host where optional.Warning: fwrite(): supplied argument is not a valid stream resource in /home/content/t/r/a/tradingtresure/html/lib/http.php on line 20
Warning: feof(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 25
Warning: feof(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 25
Warning: feof(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 25
Warning: feof(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 25
Warning: feof(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 25
Warning: feof(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 25
Warning: feof(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 25
ETC...
Same thing...superdezign wrote:Take error suppression of of fsockopen and see what you get.
Code: Select all
$socket = fsockopen($url['host']) or die("Error: unable to open a socket connection.");
Code: Select all
$socket = @fsockopen($url['host']) or die('Cannot open the host '.$url['host']);JellyFish wrote: changed the line to:
And I get the death.Code: Select all
$socket = fsockopen($url['host']) or die("Error: unable to open a socket connection.");
Make use of &$errno and &$errstr to see the actual failure.PHP Manual wrote:fsockopen ( string $hostname [, int $port [, int &$errno [, string &$errstr [, float $timeout]]]] )
Spades:Error: unable to open a socket connection with http://www.linkpointcentral.com
Code: Select all
$socket = @fsockopen($url['host']) or die('Error: unable to open a socket connection with '.$url['host']);
... Wait, you use linkpoint? Okay, well they have an API, as you might know, that allows you to use cURL methods and what-not. But I wasn't able to use the API because of my server.miro_igov wrote:So you can't connect. Now add in the die( ............ 'The error is: '.$errstr);
Edit:Especially for linkpoint i will prefer to use cURL.