Page 1 of 1

Socket Connection

Posted: Wed Jul 06, 2005 2:14 pm
by Umair_Ahmad_Khan
First I am 0.00 done with php, have no experience using this language. second what i want is i need little help and assistance. I am thinking to make a board game to play it online now as i have little knowledge that says php is for server side basically. so i am thinking to make clients in java and C# and i will make server in php. will this be good idea??. now on php.net i found that i can create socket connections etc but the thing i havn't find is how to execute that code. is there any thing like i have to make executable file of my code or execution means saving it in php page and just running the page well that doesn't make sense.
there are certain other reasons for not making complete sever-client in one language.
Umair Khan

Posted: Wed Jul 06, 2005 3:06 pm
by Chris Corbyn
PHP doesn't have to run in a web page although it's an interpreted scripting language. i.e. It is read and executed and then it is done with.

You can also run PHP as a CLI application by passing it through the php interpreter.

Code: Select all

-- bash -$ php phpfile.php
To save that hassle you can add the shebang line:

Code: Select all

#!/usr/bin/php
<?php

echo "Hello World!\n";

?>
and chmod +x it so it can execute then after that you just point to it (or put a symbolic link in your bin dir if you prefer). You don't even s read and executed and then it is done with.

You can also run PHP as a CLI application by passing it through the php interpreter.

Code: Select all

-- bash -$ php phpfile.php
To save that hassle you can add the shebang line:

Code: Select all

#!/usr/bin/php
<?php

echo "Hello World!\n";

?>
and chmod +x it so it can execute then after that you just point to it (or put a symbolic link in your bin dir if you prefer). You don't even need the .php extension if you add the shebang ;)

Code: Select all

-- bash -$ ./file.php
[Um... I think I've wandered off-topic here :?]

Should you need something regularly repeated, use CRON to re-run it at set intervals. PHP isn't the t5a9]

To save that hassle you can add the shebang line:

Code: Select all

#!/usr/bin/php
<?php

echo "Hello World!\n";

?>
and chmod +x it so it can execute then after that you just point to it (or put a symbolic link in your bin dir if you prefer). You don't even need the .php extension if you add the shebang ;)

Code: Select all

-- bash -$  with.

You can also run PHP as a CLI application by passing it through the php interpreter.

[code]
-- bash -$ php phpfile.php
[/code]

To save that hassle you can add the shebang line:

[php]
#!/usr/bin/php
<?php

echo "Hello World!\n";

?>
[/php]

and chmod +x it so it can execute then after that you just point to it (or put a symbolic link in your bin dir if you prefer). You don't even need the .php extension if you add the shebang ;)

[code]
-- bash -$ ./file.php
[Um... I think I've wandered off-topic here :?]

Should you need something regularly repeated, use CRON to re-run it at set intervals. PHP isn't the tool for everything server side, but it is pretty diverse. If it doesn't do what you need you'll have to look at other languages.

ok ...

Posted: Wed Jul 06, 2005 3:52 pm
by Umair_Ahmad_Khan
tell me bout this first line is it path ... and for what.. i m using windows actually thats why i am confused

#!/usr/bin/php


edit:
oh. if i have to rerun it again and again then i think i better use some other language hmmm thanks

Posted: Wed Jul 06, 2005 4:33 pm
by Chris Corbyn
Yeah a shebang line is more of a *nix thing. It gives the path to the program which will be executing the script.

Either way, windows or unix you would unfortunately have to repeat-run it as you say if you wanted something which is constantly working.

As you've probably decided already, PHP isn't what you need for this task ;)

Posted: Wed Jul 06, 2005 5:28 pm
by timvw
Well, from years ago, doing some perl/cgi on windows and apache...

#!c:/bin/perl.exe

is a nice she-bang too :p



Writing a little server in Java or C# should be accomplished quite easily. Or just look at sourceforge for an existing project, and rip out the parts you need ;) For example the design of http://jetrix.sf.net is nice ;)