6

I'm really new in client-server and socket programming.

Is it possible to write client-server file transfer and upload large file (4GB+) using php socket programming? Or should I use php ftp?

3 Answers 3

5

Though it should be possible to write both the client & server parts with sockets in PHP, I would almost certainly opt for PHP's FTP extension, as most of the work handling files and building/tearing down connections is already done for you. http://www.php.net/manual/en/book.ftp.php

Sign up to request clarification or add additional context in comments.

Comments

2

You could with sockets. However, you would save so much time by just using PHP's built in FTP functions. However, if you want to learn more about sockets here are some links.

http://php.net/manual/en/book.sockets.php

http://beej.us/guide/bgnet/output/print/bgnet_USLetter.pdf

http://www.devshed.com/c/a/PHP/Socket-Programming-With-PHP/

Comments

1

Of course it's possible. If you can send it over http you can use sockets. You just have to specify the right headers describing the data you want to send across and then send the bytes across. Here's some example code:

$fp = fsockopen("localcook", 80, $errno, $errstr, 30);
$outbody = getPureJSON();
//$out = getHeaders2($outbody);
$out = getKOHeaders($outbody);
echo "Message Sent:<br/>";
echo $out;
fwrite($fp, $out);
echo "<br/>Message Received:<br/>";
while (!feof($fp)) {
    echo fgets($fp, 128);
}

fclose($fp);

Hope this helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.