Server Administration
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesServer Administration

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old November 29th, 2005, 09:55 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
php running as a program?

hi i heard it is possible to let php run as a programm with linux and or windows. So example if you want to listen to a socket with php the you would have to run it as a programm. So how does that work ?

background: I want to program a server with php and socket connections, so all information would be great , links etc

thanks

Reply With Quote
  #2  
Old November 29th, 2005, 04:51 PM
icandothat's Avatar
icandothat icandothat is offline
Moderator
Click here for more information.
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 1,548 icandothat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 2 h 20 m 4 sec
Reputation Power: 3
RE: php running as a program?

you can run a php script on your server the same way you run a wsh or perl or batch file. Here is a tcp server script I stole from php developers cook book page 359.

SOLUTION
use php's lower level socket funtions along with the set_time_limit() function to create a simple server:
Code:
<?php
set_time_limit(0);

$addr = "127.0.01";
$port = 5000;

$sock = socket(AF_INET, SOCK_STREAM, 0);
if($sock < 0)
   die(strerror($sock));

if(($ret = setsockopt($sock, SOL_SOCKET, SO_REUSEADDR< 1))<0)
   print strerror($ret);

if(($ret =bind($sock, $addr, $port)) < 0)
  die(strerror($ret));

if(($ret = listen($sock, 10)) < 0)
   die(strerror($ret));

while (($csock = accept_connect($sock)) >= 0){
   // .. manipulate $csock here.
}

close ($sock);

?>


I didn't check this for parse errors

To create a TCP server, you must first create a new socket witha domain of AF_INET and a type of SOCK_STREM. Then you bind() that socket to an addresss and port. Following that, you have to tell PHP to listen() on that socket, with a maximum number of conections specified by the second argument. Finally , ;you have to accept new conections to teh socket. For that, you can use PHP's accept_connect() funciton, which will accpet a new socket that can be both read from and listened to. When you close this socket, a new socket will be accepted.

again this is straight from PHP developer's cook book
copyright 2001 by sterling hughes


Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesServer Administration > php running as a program?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway