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!
I'm not sure I understand the question or problem, but...
If the script connects to an FTP server when invoked from CLI and nothing when invoked from a browser...I would first suspect that maybe it's the shebang line at the start of the script??? Try removing that and see what happens...
Secondly...PHP CLI and Apache are two different executables.
Step through the script when executed through the browser and make sure all appropriate extensions are installed/loaded.