w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Will select (or epoll) mark a socket as readable if there is data on the socket prior to adding the socket to the list of monitored file descriptor
will select now immediately let me know that the socket is readable? Yes. What, if in step 5, the peer does not send me any data but say, since a FIN. Will select still tell me that the socket is readable Yes. in summary, the question is if select(or any of its variants such as epoll) indicate that a socket is readable if there has been any activity on the socket prior to including the socket in the list of monitored file descriptors and assuming that the application has read no data from the socket Yes.

Categories : Sockets

FastCgi vs PHP-FPM using Nginx web server
PHP-FPM is much better than the old FastCGI handling of PHP. As of PHP 5.3.3 PHP-FPM is in core and the old FastCGI implementation isn’t available anymore. My answer was just down voted (after being online for quite some time) and I understand why, so here is a list why PHP-FPM is actually better than the old FastCGI implementation. First of all, it was known for quite some time that the FastCGI implementation is bad in the PHP community. A page that documents that can be found at https://wiki.php.net/ideas/fastcgiwork where it says: php-cgi is not useful in production environment without additional “crutches” (e.g. spawn-fcgi from lighttpd distribution or php-fpm patch). This project assumes integration of such “crutches” and extending php-cgi to support for different prot

Categories : Nginx

How to use FastCGI to send an image
Rather than copying files from the filesystem yourself an echo'ing them back to Apache, why not use something like https://tn123.org/mod_xsendfile/ . All your response includes is standard headers and a special X-Sendfile header. The server module reads the file from the filesystem and returns it to the client.

Categories : Perl

Nginx + fastcgi multithreading
The problem is solved. Use FCGX_OpenSocket and umask(0) in order to let socket accept. This will give you real multithreaded application. #include <pthread.h> #include <sys/types.h> #include <stdio.h> #include "fcgi_config.h" #include "fcgiapp.h" #define THREAD_COUNT 8 #define SOCKET_PATH "/var/run/myfcgiserver.sock" // your unix socket file static int socketId; static void *doit(void *a) { int rc, i; FCGX_Request request; char *server_name; if(FCGX_InitRequest(&request, socketId, 0) != 0) { printf("Can not init request "); return NULL; } printf("Request is inited "); for(;;) { static pthread_mutex_t accept_mutex = PTHREAD_MUTEX_INITIALIZER; printf("Try to accept new requ

Categories : C++

Using Lua in nginx to pass a request to FastCGI
Use the ngx.location.capture() method to perform a subrequest to a predefined location block. Then, from within the location block, perform the external, FastCGI request. Because the subrequest itself isn't actually a network operation, but is performed purely within nginx C-based environment, there's very little overhead. Further, because the FastCGI request and other "proxy_pass"-type requests are event-based, nginx can operate as an efficient intermediary. As an example, you could have the following: location / { access_by_lua ' response = ngx.location.capture("/my-subrequest-handler") if response.status == 404 then return ngx.exit(401) -- can't find/authenticate user, refuse request end ngx.say(response.status) '; # other nginx config stuff here as

Categories : Nginx

Nginx + FastCGI + C throws 502 Bad Gateway
Its look like your php5-fpm is not running om 8000 port as you included in nginx conf fastcgi_pass 127.0.0.1:8000; You can verify your php5-fpm is running on that port by using following commands grep -Hr "8000" /etc/php5/fpm/pool.d For setup php5-fpm on 8000 open following file and change listen to 8000 port vim etc/php5/fpm/pool.d/www.conf now search listen and replace it with following line listen = 127.0.0.1:8000 Save the file and restart php5-fpm

Categories : C

Managing Nginx FastCGI cache files
From reading http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_cache_path I would note that cache size and contents are managed through following options to fastcgi_cache_path directive: inactive: "Cached data that are not accessed during the time specified by the inactive parameter get removed from the cache regardless of their freshness. By default, inactive is set to 10 minutes." So I would suppose that with default settings all files that were not accessed within last 10 minutes should be removed; max_size: "The special cache manager process monitors the maximum cache size set by the max_size parameter. When this size is exceeded, it removes the least recently used data.". I would guess that you do not have max_size limit set at all. So with large number of objects

Categories : Nginx

How do I get requestId of FCGI process in Perl using Net::FastCGI?
You wouldn't. There's no sense in using Net::FastCGI when you're already using FCGI. The request ID, if you need it, is available in $request->{id} after calling $request->Accept. It's not clear what you mean by "receives and returns same request IDs" though.

Categories : Perl

PHP Uploading with FastCGI on IIS 7.5 stalling/taking forever
Welp, that was stupid. I just asked around and someone did infact turn on "intrusion prevention" at the router level for the one server that was having issues. Disabling that seems to resolve the problem.

Categories : PHP

My nginx + fastcgi configuration downloads php files instead of executing them
Your php code is being displayed directly because it's not being sent to the php engine, that means the location block is being matched and the php file is being served, but the php file isn't being captured by the php block, so your problem is in the php block. In that block you have 2 fastcgi_pass, one with a port (9000) and the other to a unix socket, you can't have both together, but since you've tagged your question with fastcgi so I'll assume you are using fastcgi, try commenting this line #fastcgi_pass unix:/var/run/php5-fpm.sock;

Categories : Nginx

Plesk auto update crashes FastCGI support
SElinux? What is permissions on /var/www/cgi-bin/cgi_wrapper/cgi_wrapper? should be -rwxr-xr-x 1 root root 3660 Jun 6 2012 /var/www/cgi-bin/cgi_wrapper/cgi_wrapper What in /var/log/apache2/suexec.log or /var/log/httpd/suexec_log ? Permissions on suexec ? Find all files, check permissions: find / | grep suexec Custom php.ini on domain / custom php settings on domain? Is their is compatible with current PHP version? What happens if run php script in cli mode like: php -c /var/www/vhosts/domain.tld/etc/php.ini /var/www/vhosts/domain.tld/httpdocs/index.php Connection reset by peer: mod_fcgid: error reading data from FastCGI server

Categories : Misc

Random PHP FastCGI / Connection reset by peer / incomplete headers
This issue is generally not just Host specific, it is developer related as well, depending on the configuration. However some hosts are rather strict with FastCGI and will limit your capabilities. It is generally easier to run without using FastCGI and just use mod_php unless you have specific need to use FastCGI in your application. We would need to see your fcgi wrapper (what's in /dev/shm/blackmou-php.fcgi) or .htaccess for FastCGI spawning, to better assist you without knowing which files and the code that is on those files the issue occurs with. Also do your hosts use Apache, LightHttpd, or Nginx (or combination)? At that point I strongly suggest updating to use PHP 5.3.9+ As this can be caused by any number of issues, FastCGI effectively prevents your site/scripts from being attack

Categories : PHP

How to limit max file size for upload in nginx for special location with fastcgi
Is the URI really and exactly http(s)://example.com/account/personal_info/documents/ in your browser? If so, be more specific in your configuration to make sure nginx applies the correct location block. location = /account/personal_info/documents/ { # ... }

Categories : Nginx

How to code a simple php5-fastcgi stdin stdout one time shot for now
To work with stdin / stdout you have to deal with them like files using the php:// wrappers $stdin = fopen("php://stdin", "r"); and $strout = fopen("php://stdout", "w"); Then you can use the normal file function (fgets, fread, fputs and fwrite etc...) to manipulate the values.

Categories : PHP

InnoDB table errors: Doesn't exist/exist. Orphaned tables? Invisible database in mysql command clients
Ok nevermind. I finally fixed it. After adding the lines [mysqld] innodb_file_per_table to my.cnf, I dropped the whole database. Of course I dumped it earlier and recreated + restored the database. No problems here.

Categories : Mysql

lighttpd, php, fastcgi - individual virtual host settings for notices warnings and error showing
Not sure, are looking for something like this <VirtualHost *:80> ServerName example.com DocumentRoot /var/www/domains/example.com/html ErrorLog /var/www/domains/example.com/apache.error.log CustomLog /var/www/domains/example.com/apache.access.log common php_flag log_errors on php_flag display_errors on php_value error_reporting 30719 php_value error_log /var/www/domains/example.com/php.error.log </VirtualHost> The reason 30719 is used is below All errors and warnings, as supported, except of level E_STRICT prior to PHP 5.4.0. 32767 in PHP 5.4.x, 30719 in PHP 5.3.x, 6143 in PHP 5.2.x, 2047 previously . Read here for this. You can use php_value error_reporting 2147483647 The above number, according to documentation should enable 'all' e

Categories : PHP

Update if exist, insert row if not exist in MySQL
Try with ON DUPLICATE KEY like $sql = "INSERT INTO `table2` (Col2, Col3) VALUES ('val1', 'val2') ON DUPLICATE KEY UPDATE Col2='val1', Col3='val2'"; EDIT : INSERT INTO table2 (ColB , ColC) (SELECT ColB.b,ColC.b FROM table1 b LEFT JOIN table3 c ON c.IDA = b.IDA LEFT JOIN table2 a ON a.IDB = c.IDB WHERE IDB = 111 ) ON DUPLICATE KEY UPDATE ColB = ColB.b ColC = ColC.b And Try to avoid mysql_* statements due to the entire ext/mysql PHP extension, which provides all functions named with the prefix mysql_*, is officially deprecated as of PHP v5.5.0 and will be removed in the future. There are two other MySQL extensions that you can better Use: MySQLi and PDO_MySQL, either of which can be used instead of ext/mysql.

Categories : PHP

explain behavior of accept function when is called on active socket (instead of passive socket)
Most propably the call to accept() failed. You shall test whether accept() returned -1 prior to looking into cliaddr. Also the code you show close()es the listing socket (down in do_Work()) after the first accept(). Any following accept() though will surely fail.I missed the call to fork() As per Duck's comment: However as long as the call to listen() is commented out accept() has to fail.

Categories : C

Can socket objects be shared with Python's multiprocessing? socket.close() does not seem to be working
The problem is that the socket is not closed in the parent process. Therefore it remains open, and causes the symptom you are observing. Immediately after forking off the child process to handle the connection, you should close the parent process' copy of the socket, like so: while True: print "accepting" c, _ = s.accept() p = Process(target=process, args=(c,)) p.start() print "started process" c.close()

Categories : Python

node.js + socket.io + redis architecture - horizontal serverscaling socket connections?
When you're horizontally scaling, you need to share a datastore between your servers. Conveniently, you already have an ideal one, which is Redis. Instead of keeping your socket mapping in an array, you need to push it into Redis, and do lookups from there. Then, you can either decide to have servers send messages to each other, or, more scalably, send the messages through Redis as well. So, each server would look at it's queue on Redis to see what messages it should send to which sockets. When a server receives a message, it will push it into Redis addressed to the server that should deliver it. If the ordering of messages matters to you, I would recommend looking at https://github.com/learnboost/kue as layer on top of Redis.

Categories : Node Js

How to receive web socket message from server in client side by html5 socket api
Its always good practice before connecting to websockets, to check if the browser your user is using supports them....like so.... //First check for firefox, and set it to regular websocket...since Mozilla API is differently named if (window.MozWebSocket) { window.WebSocket = window.MozWebSocket; } //Then continue with checking var connection = {}; function connect() { if(window.WebSocket != undefined) { if(connection.readyState === undefined || connection.readyState > 1) { connection = new WebSocket('ws://127.0.0.1:80'); } } }

Categories : PHP

GCDAsyncSocket connect fails -- only when socket variable is called "socket". What is happening?
As @bburn suggested, this is a symbol collision. There is a BSD socket() function which GCDAsyncSocket uses. If you look at the EXC_BAD_ACCESS in the debugger, you'll see that it's actually failing when attempting to call socket() because it's resolving the function address to that of your variable. Aside from renaming the variable, you can do a couple of things (I think it would be a good idea to do one of these things even if you also rename the variable): Declare the variable to be static. This will confine the scope of your variable to that file so that it cannot be accidentally resolved by GCDAsyncSocket. It would be a good idea to remove it from the global namespace anyway. Make it a private member variable. To change it to a private member variable, change this: @implemen

Categories : Objective C

Closing socket after subprocess.Popen leaves socket in TIME_WAIT as long as child process is still running
Closing socket after subprocess.Popen leaves socket in TIME_WAIT as long as child process is still running No it doesn't. It leaves it in TIME_WAIT for a fixed amount of time, 2 or 4 minutes. After the close it has nothing to do with the child process at all.

Categories : Python

NodeJS Dynamically Load server instancess for a socket using socket.io
You are exporting a function, and not an object. This means that the correct call should be sv(io) and not sv.init(io). If you want to expose the init function, you have to use module.exports.init = init.

Categories : Javascript

Socket closed before able to read from ObjectInputStream(BufferedInputStream(Socket.getInputStream))
You can't use a buffered input stream and another kind of stream on the same socket. The buffered stream will steal data from the other one. Make up your kind the ObjectInputStream will do everything you need. Just use that.

Categories : Java

Java Socket server not recieving data from client socket
Your client doesn't close the socket. Your server reads the socket until EOS, which will never arrive as your client doesn't close the socket. NB don't handle client I/O in the accepting thread. Start a separate thread.

Categories : Java

Why do I received UDP socket answer randomly with Asynchronous UDP client socket?
That's how UDP works. UDP is a protocol that provides an unreliable, unordered data delivery between devices connected to an IP network. It is generally considered a "layer 4" protocol in the OSI stack. One popular use of UDP is for transport of time-sensitive information, such as Voice over IP. UDP is specified in RFC 768. http://www.techabulary.com/u/udp/ You either need to use TCP, or be prepared to handle the out-of-order (and possibly completely missing) responses. SCTP is another option for your transmission protocol.

Categories : C#

Socket.io : what happen to the client(socket) after a user is disconnected? Can I/Should I remove it?
In the code above, it is setInterval that is causing the additional logging. You will need to store off the id returned from setInterval then clear it using clearInterval on a disconnect event. Something like: io.sockets.on("connection",function(socket){ var intervalId = setInterval(function(){ console.log("Server calling update collection with socket No.",socket.No); },3000); //When connection is close() socket.on("disconnect",function(){ console.log("A user disconnected"); clearInterval(intervalId); }); }) Other than that, no need to do anything else with the socket on the server side. It will get garbage collected at some point.

Categories : Node Js

A java Socket is a TCP socket. Do I send TCP header information to a website?
do I have to strip away the IP and TCP headers when sending the data through a Socket() in java? Or do I leave the TCP header intact? You don't have the TCP header to strip. You just send and receive data. I tried plain socket, but it was not connecting ... So then I tried using a blocking SocketChannel There's no difference for this purpose between Socket and SocketChannel. If you're using either of them you are only concerned with the data payload, not the IP or TCP headers. Also if don't mind answering another question for me. When I get the payload I try to search for "GET" in hex values (0x47,0x45,0x54) to find the HTTP header, but I never find one. Is this right? I check the IP address requested and its asking for google.com. One thing though is that the port is 443 wh

Categories : Android

How to change the folder where socket.io is fetching the socket.io.js JavaScript file?
socketio sever when receives the request '/socket.io/socket.io.js' , it dynamically builds the content ( considering the transports configured to be supported by the server ). The file is neither served from public / node modules.

Categories : Node Js

How to make client socket wait for server socket
boolean scanning=true; while(scanning) { try { socketChannel.open(hostname, port); scanning=false; } catch(ConnectionException e) { System.out.println("Connect failed, waiting and trying again"); try { Thread.sleep(2000);//2 seconds } catch(InterruptedException ie){ ie.printStackTrace(); } } } This is the code for sonics comment

Categories : Java

boost::asio::ip::tcp::socket -> how to query the socket state?
You can try to use ip::tcp::socket::get_option and get error state with level SOL_SOCKET and option name SO_ERROR. I'm surprised that I have not found the ready boost implementation for it. So you can try to meet GettableSocketOption requirements an use ip::tcp::socket::get_option to fetch the socket error state.

Categories : C++

GET http://localhost:3000/socket.io/socket.io.js 404 (Not Found)
Can you try this http = require('http'); var app = express(); var server = http.createServer(app); var io = require('socket.io').listen(server); I guess, you will have to instantiate the socketio server.

Categories : Node Js

Chat client - Socket and server socket concurrently
ServerSocket blocks and that's it. But if you only want peer-to-peer communication between two connected parties and nothing more then this behavior is not a problem. You just need two programs: server and client. Server block until it gets connection from client and client blocks until it gets connection. If you want to implement Java IO in single thread you should use Java Nio. There are lots of tutorials for that in internet. For example http://tutorials.jenkov.com/java-nio/server-socket-channel.html. Also it seems that you are not very familar with networking and sockets so it might be beneficial to use some layer instead of raw sockets. Maybe you should consider JeroMQ (https://github.com/zeromq/jeromq) for implementing communication between programs.

Categories : Java

PHP socket sends data but Java socket is not receiving
String str = br.readLine(); expect a which is not sent by the PHP program. Add this : socket_write($socket, "Hello " ); // <<<=== ' ' added

Categories : Java

Abrupt termination of server (Socket operation on non-socket)
This is actually a linux problem, because you're trying to use recv and send to read from and write to STDIN (which is probably a terminal not a socket). Unlike most UNIX variants, in Linux, send and recv can only be used on sockets, not on any file descriptor. For a terminal, you need to use read and write. There's also the issue that it's weird to write to STDIN -- normally you only read from STDIN and write to STDOUT. But as long as STDIN is somethine like a terminal you can write to, it would be ok.

Categories : C

Socket error - with simple socket programming using python
The problem with windows sockets is that they don't actually die when you close them unless you tell them to. Try adding the following code after you initialise the socket and see what happens. l_onoff = 1 l_linger = 0 s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', l_onoff, l_linger)) The documentation for Lingering can be found at MSDN. also change your shutdown to: s.shutdown(socket.SHUT_RDWR) This should close all connections immediately if windows behaves itself. Which will prevent the buffer error caused by too many sockets lingering.

Categories : Python

UNIX SOCKET - direct write into socket's memory possible?
The socket buffer is owned by the kernel, you will never be allowed to write into kernel space. Never, ever. Too much of a security risk. The only way to do zero-copy is to use vmsplice(2), but it is not officially supported for sockets and is not recommended to use for anything other then pipes. If you do decide to use vmsplice, keep in mind that you must then commit your data in chunks of pages sysconf(_SC_PAGESIZE). Also it is a Linux only syscall and not portable.

Categories : C

SQL SERVER 2012 IF EXIST and IF NOT EXIST
SQL Server has MERGE http://msdn.microsoft.com/en-us/library/bb522522(v=sql.105).aspx that you can use as an UPSERT. Here's an example copied from the docs (Example A): MERGE dbo.FactBuyingHabits AS Target USING (SELECT CustomerID, ProductID, PurchaseDate FROM dbo.Purchases) AS Source ON (Target.ProductID = Source.ProductID AND Target.CustomerID = Source.CustomerID) WHEN MATCHED THEN UPDATE SET Target.LastPurchaseDate = Source.PurchaseDate WHEN NOT MATCHED BY TARGET THEN INSERT (CustomerID, ProductID, LastPurchaseDate) VALUES (Source.CustomerID, Source.ProductID, Source.PurchaseDate) OUTPUT $action, Inserted.*, Deleted.*;

Categories : Mysql

Dojox socket exception with node.js socket.io
Seems to be an unresolved ticket for a while https://bugs.dojotoolkit.org/ticket/16572 edit: https://github.com/dojo/dojo/commit/3beccffc21fbcd3e21681fc74a29b0c56a31572f

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.