0

A friend of me said its not good to use FTP on PhP, since there are plenty of ftp_connect() since it ends when scripts is over. He said I could "fork" it. What is it excatly?

user893856
  • 1,039
  • 3
  • 15
  • 21

2 Answers2

1

There are multiple possibilities and it may not be obvious, what he thought by saying that.

1. He wants you to fork the code of the script

In this case forking means separating your solution from the main script. It is rather loose interpretation, but makes sense if the script could be executed separately, eg. by cronjob. This way you can create separate script which will be able to work longer (or you can even switch off its termination when user disconnects).

2. He wants you to fork PHP :)

Maybe he joked that you can do better and create your own version of PHP :) Or maybe it was not a joke? :)

3. Multithreading?

Maybe he thought about multithreading? But PHP is not well suited for that (see solutions for this).

Community
  • 1
  • 1
Tadeck
  • 132,510
  • 28
  • 152
  • 198
0

My guess is that he meant that an FTP client written in PHP under Apache has the issue that the connection is closed after every request, since your script ends every time.

If I'm right, by forking he referred to spawning a separate process on the server that keeps the FTP connection alive while Apache handles multiple requests. That is, the FTP client is running as a sort of daemon on the web server, and your PHP scripts communicate with that daemon. This way, you only have to connect once to the server, while Apache can handle different requests.

Forking means detaching a child process form its parent, and make it run independently. In this example, the process that connects to the FTP server is forked, and as such detached from its parent - the script from the web request, that is going to be terminated after the request is done.

Pelle
  • 6,423
  • 4
  • 33
  • 50