I cannot connect to server with fsockopen, please help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

I cannot connect to server with fsockopen, please help!

Post by kaisellgren »

If someone can answer me why this doesn't work?

$fp = fsockopen("psychclassics.yorku.ca/Abbott",80,$errno,$errstr,0.5);

It does not create sock connection :(
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

where is your protocol string ? http:// ?
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Post by kaisellgren »

I have also tried that but no lucky:

Warning: fsockopen() [function.fsockopen]: unable to connect to http://psychclassics.yorku.ca/Abbott:80 (Unable to find the socket transport "http" - did you forget to enable it when you configured PHP?) in C:\Ohjelmat\WAMP\www\test.php on line 8
Unable to find the socket transport "http" - did you forget to enable it when you configured PHP? (40)

OH THAT'S BECAUSE THERE IS NOT http://psychclassics.yorku.ca/Abbott:80 BUT HOW DO IT THE PORT? THIS IS ALSO WRONG: http://psychclassics.yorku.ca/Abbott/:80 <--- HOW TO GET RID OF THE PORT?
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post by Mordred »

fsockopen connects to a SERVER
the server is psychclassics.yorku.ca, not psychclassics.yorku.ca/Abbott
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Post by kaisellgren »

Okay I managet to connect to a html file with fopen(), but how do you connect to a .txt file? By connecting I mean that I'm able to read the lines of txt.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

If enabled use php's url wrappers.

Code: Select all

<?php
$contents = file('http://psychclassics.yorku.ca/Abbott/');
foreach($contents as $line) {
	echo '# ', htmlentities($line);
}
?>
see http://de2.php.net/manual/en/ref.filesy ... -url-fopen
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Post by kaisellgren »

That works well for html pages but does not work for a txt file ...
Post Reply