SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,146
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post help me where to put this file

    Please help me on this,I am creating simple socket connection that listen to port 80 and i will put this to my server and I am using wampserver,...where do i put this mysocket.php ? in the root of my www?



    Thank you in advance.

  2. #2
    SitePoint Zealot bronze trophy xMog's Avatar
    Join Date
    Mar 2011
    Posts
    151
    Mentioned
    3 Post(s)
    Tagged
    2 Thread(s)
    @jemz Can you show us what that mysocket.php file contains?

  3. #3
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,146
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by xMog View Post
    @jemz Can you show us what that mysocket.php file contains?
    This is the socket file that i want to put in my server.

    Code:
    <?php
    // Server IP address
    $address = "xx.xxx.xxx.xxx";
    // Port to listen
    $port = 80;
    
    $mysock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    
    socket_bind($mysock,$address, $port) or die('Could not bind to address'); 
    socket_listen($mysock, 5);
    $client = socket_accept($mysock);
    
    // read 1024 bytes from client
    $input = socket_read($client, 1024);
    
    // write received gprs data to the file
    writeToFile('gprs.log', $input);
    
    socket_close($client);
    socket_close($mysock);
    ?> 
    
    <?php
    function writeToFile($strFilename, $strText) { 
        if($fp = @fopen($strFilename,"w"))  { 
              $contents = fwrite($fp, $strText); 
              fclose($fp); 
              return true; 
        } else { 
          return false; 
        } 
    } 
    ?>

  4. #4
    SitePoint Zealot bronze trophy xMog's Avatar
    Join Date
    Mar 2011
    Posts
    151
    Mentioned
    3 Post(s)
    Tagged
    2 Thread(s)
    This doesn't look like a script that should be called from a web server or URL, this is a "command line" script. I'm not sure it will work on Windows, but you could give it a try.

    Here's the official doc for command line PHP :http://www.php.net/manual/en/install...ommandline.php

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    The documentation for using php sockets clearly provides a resource for learning more about them and the URL to a resource for those whom are unfamiliar :/

    http://www.php.net/manual/en/intro.sockets.php
    The only code I hate more than my own is everyone else's.

  6. #6
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,438
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Hi jemz,

    Quote Originally Posted by jemz View Post
    Please help me on this,I am creating simple socket connection that listen to port 80 and i will put this to my server and I am using wampserver,...where do i put this mysocket.php ? in the root of my www?
    If you're writing a script to listen to a port, you don't want to be serving it via wampserver. A HTTP server like Apache (or nginx) is listening on a port (usually port 80) for incoming HTTP requests and then returning a response. To listen on a port with your script, you'll need to run it from the command line (as xMog suggests), and probably open the corresponding port on your firewall. Also, I wouldn't choose port 80 for you script, as it's used by web servers and by programs like Skype.
    "There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies."

  7. #7
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,146
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post

    @Xmog,@fretburner,@oddz

    Code:
    C:\PHP5\php.exe -f "C:\PHP Scripts\script.php" -- -arg1 -arg2 -arg3
    what is that arg1 arg2 arg3 stands for?


    Thank you in advance.

  8. #8
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,438
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Quote Originally Posted by jemz View Post
    what is that arg1 arg2 arg3 stands for?
    They are just examples to show how you would pass arguments to a script from the command line.
    "There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies."


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •