hey
can i transfer pictures through sockets through php? how can i do it if its posible.i want to send n receive pictures

Dani AI

Generated

asked about sending images to a C++ program and getting them back. 's local-file + invoke approach is a practical, simple choice for same-host processing, but the statement that "You can't pass things around using sockets" is incorrect: sockets are a standard way to transfer binary data between processes and machines. The main decision is transport (local filesystem / IPC vs network sockets / HTTP) and framing (how the receiver knows where one image ends and the next begins).

For quick reference:

  • Local, same-host: save the upload to a temp file and spawn the C++ process with the filename (easy, atomic rename avoids partial reads), or use a Unix domain socket / named pipe for lower latency and no filesystem churn.
  • Remote or service-oriented: run the C++ component as a TCP/HTTP server. PHP can POST multipart/form-data or send raw bytes; use a small header (filename + length) or HTTP Content-Length so the C++ side knows how many bytes to read.
  • Streaming/large files: implement length-prefixed framing and loop on reads/writes until the full payload is transferred; do not assume a single read returns the whole image.

Important cautions: always use binary-safe I/O (fread/fwrite or recv/send with correct flags), handle short writes/reads in a loop, set sensible timeouts, use TLS/HTTPS for network transfers, and avoid base64 unless necessary (adds ~33% overhead). For implementation details see the PHP sockets documentation (PHP sockets manual) and PHP stream sockets (stream_socket_client). For framing concepts see .

Recommended Answers

All 3 Replies

Where do you want to transfer images from, and where to?

i want to transfer images to a C++ program and after some processing want to get back from C++ program

Well php will store the images on the file system somewhere. If you write your C++ program, you could then use the PHP script to call the C++ program. Then when the C++ program is done, if give back a report of some sort and saves the processed pictures to the same place if unedited, or else where if the images were edited in some way. You can't pass things around using sockets.

If you would like to get into image processing using C++ and php, have a look at imagemagick.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.