HI
I am new to php
I would like to ask how I can insert a C source code into a php file
please help
I have a C scheduling algorithm that I'd like to use for my site that I am developing using php/mysql but I don't know how.

Please help

Dani AI

Generated

Short practical summary and a safe, low-friction workflow for integrating a C scheduling algorithm into a PHP/MySQL site (reacting to , and ).

Raw C source can’t simply be dropped into a .php file. Common, workable routes are: (1) port the core algorithm to PHP for easiest integration and maintenance; (2) keep the C code compiled and call it from PHP as a separate process (stdin/stdout, files or JSON); (3) expose the C code as a long‑running service (Unix socket or TCP) and talk to it from PHP; (4) create a PHP extension or use a foreign-function interface/wrapper so PHP calls the C directly. Each choice has tradeoffs in development time, runtime speed, portability and maintenance effort.

Suggested step-by-step workflow

  1. Define clear input/output formats (plain arrays or JSON) that map DB rows (teams, constraints) to the scheduler and back.
  2. Build a tiny test harness first (feed a few teams, confirm output). Keep the harness language-agnostic so it can be used by a PHP port or the compiled binary.
  3. Start by porting a minimal, correct version to PHP to validate results against the C output. This proves correctness and gives a baseline performance number.
  4. If perf is unacceptable, move to a compiled-wrapper or daemon approach (less work than a full extension). A true PHP extension or FFI/wrapper is justified only when sustained high throughput and low latency are required.

Operational cautions

  • Sanitize and validate any inputs passed to external processes; avoid exec with untrusted input.
  • Use transactions or a job-lock (single scheduler worker) to prevent simultaneous conflicting runs.
  • For long runs, perform scheduling as a background job (cron/queue/worker) instead of in a web request.

Given the offers already in-thread, porting a minimal core and verifying results is the fastest, lowest-risk path before committing to a compiled extension or daemon.

Recommended Answers

All 5 Replies

Simple answer: Your algo needs to be ported to PHP. There is no way to implement C/C++ code into a php file.

The only way this works would be writing an extension for PHP. This extension is loaded by the php engine and provides your functionality under special function names.

Have a look at http://www.php.net and the PECL or PEAR subsites.

Member Avatar for Member #46692

WHy don't you post your c algo here. I'd bet I could port it to php.

http://www.devnewz.com/2002/0909.html

This is a nice "how to" for adding your own libraries using windows. Linux shouldn't be a problem as well, if you know about C/C++ programming on different platforms.

That is the scheduling code,
I 'd really appreciate your help.
Actually I need to do scheduling for a number of teams in the mysql database.

Member Avatar for Member #46692

That is the scheduling code,
I 'd really appreciate your help.
Actually I need to do scheduling for a number of teams in the mysql database.

That looks simple enough. The only problem I can see is with that struct.

But I suppose you use use a class instead or take it out altogether.

Passing functions, again that should be simple to do.

And those bitwise operators, thankfully php supports that as well:


Have a go and see how far you get.

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.